package com.letv.android.client.episode;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.util.Log;

import com.letv.android.client.activity.AlbumPlayActivity;
import com.letv.android.client.activity.AlbumPlayRoomActivity;
import com.letv.android.client.episode.callback.ExpandableListUpdateGroupCallBack;
import com.letv.android.client.episode.callback.ExpandableListUpdateGroupNotByDateCallBack;
import com.letv.android.client.episode.callback.PlayAlbumControllerCallBack;
import com.letv.android.client.episode.parser.AlbumNewListByDateParser;
import com.letv.android.client.episode.request.ICommonRequestCallback;
import com.letv.android.client.parser.HomePageBeanParser;
import com.letv.android.client.utils.AlbumLaunchUtils;
import com.letv.business.flow.album.listener.AlbumPlayingControllerListener;
import com.letv.core.api.LetvRequest;
import com.letv.core.api.MediaAssetApi;
import com.letv.core.bean.AlbumNew;
import com.letv.core.bean.AlbumNewListByDateBean;
import com.letv.core.bean.AlbumNewListByDateBean.MonthList;
import com.letv.core.bean.DataHull;
import com.letv.core.bean.DownloadDBListBean;
import com.letv.core.bean.HomeBlock;
import com.letv.core.bean.HomeMetaData;
import com.letv.core.bean.HomePageBean;
import com.letv.core.bean.LetvBaseBean;
import com.letv.core.bean.PlayRecord;
import com.letv.core.bean.RecAlbumBean;
import com.letv.core.bean.RecommendInfoListBean;
import com.letv.core.bean.TabAllDataBean;
import com.letv.core.bean.TabIndicatorDataBean;
import com.letv.core.bean.TabOuterVideoInfoBean;
import com.letv.core.bean.TabTopicAllDataBean;
import com.letv.core.bean.TabTopicAllDataBean.TabSubject;
import com.letv.core.bean.TabTopicVideoListBean;
import com.letv.core.bean.TabVideoListBean;
import com.letv.core.bean.VideoBean;
import com.letv.core.bean.VideoListBean;
import com.letv.core.bean.VideoRelatedListBean;
import com.letv.core.constant.PlayConstant;
import com.letv.core.network.volley.VolleyRequest;
import com.letv.core.network.volley.VolleyRequest.RequestManner;
import com.letv.core.network.volley.VolleyResponse.CacheResponseState;
import com.letv.core.network.volley.VolleyResponse.NetworkResponseState;
import com.letv.core.network.volley.toolbox.SimpleResponse;
import com.letv.core.network.volley.toolbox.VolleyDiskCache;
import com.letv.core.parser.VideoListParser;
import com.letv.core.utils.BaseTypeUtils;
import com.letv.core.utils.LetvUtils;
import com.letv.core.utils.LogInfo;
import com.letv.core.utils.NetworkUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;

//import com.letv.download.bean.DownloadVideo;
//import com.letv.download.manager.DownloadManager;

public class PlayAlbumController implements ICommonRequestCallback, AlbumPlayingControllerListener {
    /*
     * 专题页面，切换专题时的剧集页面重新刷新请求
     */
    public static final String CURRENT_TOPIC_PID = "current_topic_pid";
    
    /*
     * 从 专题还是专辑点播页面进入播放页面
     */
    public static final int LAUNCH_MODE_ALBUM = 2;
    
        
    // 1:九宫格 2:长列表 3:按期数 4:专题视频剧集列表5:专题列表只显示文本项item
    private static final int GRIDVIEW_LIST_CONSTANT = 1;
    private static final int VIDEO_LIST_CONSTANT = 2;
    private static final int VIDEO_ITEM_LIST_CONSTANT = 5;
        
    private static final String GRIDVIEW_LIST_CONSTANT_STR = "1";
    private static final String VIDEO_LIST_CONSTANT_STR = "2";

    private boolean isNetSuccess;

    private boolean isCacheSuccess;
    
   
    
    /**
     * 视频列表当前页页码
     */
    public int curPage = 1;
    /*
     * 视频列表总集数
     */
    public int totalNum = 0;
    /*
     * 当前更新到的集数
     */
    public int episodeNum = 0;
    /**
     * 一页的条数
     */
    public int pageSize = 100;

    /**
     * 是否合并
     */
    public int merge = 0;

    /**
     * 合并过滤videoTypeKey
     */
    public String suggest = null;

    /**
     * 排序
     */
    public String order = "-1";

    /**
     * 视频总数
     */
    public int totle = 0;
    /**
     * 视频集合，以页数为key,主要用于文件夹格式，页数和视频列表结合的 map映射
     */
    public HashMap<Integer, VideoListBean> videos = new HashMap<Integer, VideoListBean>();

//    public HashMap<Long, DownloadVideo> getDownloadVideoHashMap() {
//        return downloadVideoHashMap;
//    }

    /**
     * 数据库 下载的数据
     */
//    private HashMap<Long, DownloadVideo> downloadVideoHashMap = new HashMap<Long, DownloadVideo>();

    /**
     * 相关数据（猜你喜欢，相关，cms）
     */
    public VideoRelatedListBean relatedBeanArray = new VideoRelatedListBean();

    /**
     * 剧集列表是否是列表形势
     */
    public boolean isList;

    private TabAllDataBean mTabAllDataBean = new TabAllDataBean();

    /*
     * 当天正在播放的视频对象
     */
    private VideoBean videoBean;

    public long vid = 0;
    public long aid = 0;
    public long cid = 0;
    public long zid = 0;

    /*
     * 是否需要在半屏情况下显示付费引导内容
     */
    private boolean mIsShowPayGuide = false;
    /**
     * 跳转小窗播放
     */
    private boolean isJumpToPip = false;

    /**
     * 是否是栏目
     * */
    public boolean isVarietyShow = false;

    /**
     * 是否是正片 和 栏目
     * */
    private boolean isVideoNormal = true;

    /**
     * 半屏页显示文字
     * 0 剧集
     * 1 期数
     * 2 列表
     * 3 相关
     * */
    public int isShowMode = 0;

    /**
     * 正片代码
     * */
    public final static String VIDEONORMAL = "180001";

    /**
     * 当前视频所在专辑（可能为空）
     */
    private AlbumNew album;

    public int mDisplayStyle = -1;

    private FragmentActivity mActivity;

    /**
     * 是否是下载状态
     */
    public boolean isDownloadState;

    /*
     * Added by chenhong, 播放记录的看过状态是否需要被记录
     * 只有剧集为gridview及expanbleListview中的gridview的看过状态需要保存
     */
    private boolean isEpisodeWatched = false;

    /*
     * 是否需要在请求页面之后刷新剧集页面数据
     */
    public boolean isRefreshDataAfterRequestPlayUrl = false;

    /*
     * 是否需要在请求页面之后刷新剧集页面数据
     */
    public boolean isRefreshRelateDataAfterRequestPlayUrl = false;

    /*
     * 是否是对比视频
     */
    private boolean mIsDolby = false;

    /*
     * 是否需要显示Toast
     */
    private boolean mIsShowToast = false;

    /*
     * 当前播放码流
     */
    private int mCurrentPlayStream = 1; // 1极速 ，2 流畅， 3 标清， 4高清
    /**
     * 状态回调
     */
    public int introductionCallBackState;
    public PlayAlbumControllerCallBack introductionCallBack;
    public int commentCallBackState;
    public PlayAlbumControllerCallBack commentCallBack;
    public int videosCallBackState;
    public PlayAlbumControllerCallBack videosCallBack;
    public int relatedCallBackState;
    public PlayAlbumControllerCallBack relatedCallBack;
    public int topicVideoListCallBackState;
    public PlayAlbumControllerCallBack topicVideoListCallBack;

    /*
     * TabsFragment
     */
    public int tabsBaseCallBackState;
    public PlayAlbumControllerCallBack tabsBaseCallBack;
    
    public PlayAlbumControllerCallBack fullControllerVideosCallBack;

    private FullRefreshData fullRefesh;
    /**
     * 播放来源
     */
    public int from;

    /**
     * 播放推荐的连播数据
     */
    private ArrayList<HomeMetaData> videoRecommendList;

    /**
     * 推荐的连播数据的当前位置
     */
    private int videoRecommendIndex = 0;

    /**
     * v5.4.1 口袋看球（判断从下载->口袋看球进来）
     */
    private boolean isFromWorldCupDownload = false;

    /** 是否返回 源应用 */
    private boolean mBackWhere;

    /**
     * 视频列表
     * */
    private VideoListBean mVideoListPlayerLibs;

    /**
     * 是否按月请求专辑列表
     * */
    public boolean isRequestAlbumListByDate = false;

    /**
     * 某些频道 栏目类 视频列表
     * */
    public AlbumNewListByDateBean albumNewListByDatePlayerLibs;

    /**
     * 非栏目 或单视频类型的相关视频
     * */
    public RecommendInfoListBean mRecommendInfoListPlayerLibs;

    /**
     * 即将播放的推荐视频信息（不能为空）
     */
    private HomeMetaData videoRecommend;

    private long htime = 0;// 扫码播放位置

    /**
     * 是否来自杜比频道
     */
    public boolean isDolby;

    /**
     * 跳过时间
     */
    private long seek;

    /**
     * 真实地址
     */
    private String realUrl;

    /**
     * 列表里面的视频是否连播到最后一个
     * */
    private boolean isPlayListLastVideo = false;

    /**
     * 是否是本地文件
     */
    public boolean isLocalFile;

    /**
     * 是否连播了下一集
     * 针对相关视频列表（因为第一次播放的相关视频列表里的当前视频不是猜你喜欢接口的数据）
     * */
    private boolean isPlayNext = false;

    /**
     * 是否销毁了播放器第一次播放
     * */
    private boolean isLaunchPlay = true;

    /**
     * 本地文件地址
     */
    private String filePath;

    /**
     * 播放视频的播放记录
     */
    public PlayRecord playRecordPlayerLibs;

    private DownloadDBListBean mDownloadDBListBean;

    // ###########################################
    // The begin the request vlist
    private boolean isPlay;

    private boolean isNextPlay;

    /**
     * 片头时间
     */
    public long bTime;

    /**
     * 总时间
     */
    public long totleTime;

    private RequestAlbumListInfo requestAlbumListInfo;

    private RequestAlbumListInfoByDate requestAlbumListInfoByDate;

    private String year;

    private String month;

    /*
     * 综艺类 按期数如 《奔跑吧兄弟》
     */
    private ExpandableListUpdateGroupCallBack mExpandableListUpdateGroupCallBack;

    /*
     * 动漫类 按剧集 如《蜡笔小星》
     */
    private ExpandableListUpdateGroupNotByDateCallBack mExpandableListUpdateGroupNotByDateCallBack;

    private RequestPlayRecommend requestPlayRecommend;    
    
    // The end of request vlist
    // ###########################################
    
    // ###########################################
    // The begin of topic
    /*
     * 专题数据集合
     */
    private TabTopicAllDataBean mTabTopicAllDataBean = new TabTopicAllDataBean();
    
    /*
     * 专题视屏列表数据集合
     */
    private TabTopicVideoListBean mTabTopicVideoListBean = new TabTopicVideoListBean();
    
    /*
     * 专题视频列表数据bean类
     */
    private TabVideoListBean mTabVideoListBean = new TabVideoListBean();
    
    public int type = AlbumNew.Type.VRS_MANG;// 是专辑还是视频
    
    /*
     * 提供给播放记录使用的下一集的Vid
     */
    private long playRecordNextVid;
    
    /*
     * 判断当前的视频是从点播还是从专题进入播放页面
     * 默认从点播进入播放页面
     */
    private boolean mPlayFromAlbumFlag = true;
    
    /*
     * 超长剧集动漫展开后是否需要续播新文件夹的第一集
     */
    private boolean isExpandListAndPlayFlag = false;

    // The end of topic
    // ###########################################
    
    public PlayAlbumController(FragmentActivity activity) {
        mActivity = activity;
    }
    
    public void setInitParams(String cid, String zid, String vid, String pid) {
        if (!TextUtils.isEmpty(cid) && TextUtils.isDigitsOnly(cid)) {
            this.cid =  Long.valueOf(cid);
        }
        if (!TextUtils.isEmpty(zid) && TextUtils.isDigitsOnly(zid)) {
            this.zid =  Long.valueOf(zid);
        }
        if (!TextUtils.isEmpty(vid) && TextUtils.isDigitsOnly(vid)) {
            this.vid =  Long.valueOf(vid);
        }
        if (!TextUtils.isEmpty(pid) && TextUtils.isDigitsOnly(pid)) {
            this.aid =  Long.valueOf(pid);
        }
    }

    /**
     * 数据库更新时 downloadVideoHashMap
     */
    public void queryDownloadVideo(final DBDownlaodInterface dbDownlaodInterface) {
        queryDownloadVideoByPid(this.aid, dbDownlaodInterface);
    }

    private void queryDownloadVideoByPid(final long pid, final DBDownlaodInterface dbDownlaodInterface) {
//        if (pid <= 0) {
//            return;
//        }
//        AsyncTask<Long, Void, ArrayList<DownloadVideo>> asyncTask = new AsyncTask<Long, Void, ArrayList<DownloadVideo>>() {
//            @Override
//            protected ArrayList<DownloadVideo> doInBackground(Long... params) {
//                Long pid = params[0];
//                return DownloadManager.getDownloadVideoByAid(pid);
//            }
//
//            @Override
//            protected void onPostExecute(ArrayList<DownloadVideo> downloadVideos) {
//                super.onPostExecute(downloadVideos);
//                downloadVideoHashMap.clear();
//                if (!BaseTypeUtils.isListEmpty(downloadVideos)) {
//                    for (DownloadVideo downloadVideo : downloadVideos) {
//                        downloadVideoHashMap.put(downloadVideo.vid, downloadVideo);
//                    }
//                }
//                if (dbDownlaodInterface != null)
//                    dbDownlaodInterface.onQueryDownloadVideoComplete();
//            }
//        };
//        asyncTask.execute(pid);
    }

    public void setTabAllDataBean(TabAllDataBean tabAllDataBean) {
        mTabAllDataBean = tabAllDataBean;
    }

    public TabAllDataBean getTabAllDataBean() {
        if (mTabAllDataBean != null) {
            return mTabAllDataBean;
        } else {
            return null;
        }
    }

    public boolean isVideoNormal() {
        return isVideoNormal;
    }


    public boolean isNetSuccess() {
        return isNetSuccess;
    }

    public boolean isCacheSuccess() {
        return isCacheSuccess;
    }

    public TabIndicatorDataBean getTabVideoListData() {
        if (mTabAllDataBean != null && mTabAllDataBean.getTabVideoList() != null
                && mTabAllDataBean.getTabVideoList().getTabIndicatorData() != null) {
            return mTabAllDataBean.getTabVideoList().getTabIndicatorData();
        } else {
            return null;
        }
    }

    public VideoBean getTabVideoInfo() {
        if (mTabAllDataBean != null && mTabAllDataBean.getVideoInfo() != null) {
            return mTabAllDataBean.getVideoInfo();
        } else {
            return null;
        }
    }

    public AlbumNew getTabAlbumInfo() {
        if (mTabAllDataBean != null && mTabAllDataBean.getAlbumInfo() != null) {
            return mTabAllDataBean.getAlbumInfo();
        } else {
            return null;
        }
    }

    public TabOuterVideoInfoBean getTabOtherVideoInfo() {
        if (mTabAllDataBean != null && mTabAllDataBean.getOuterVideoInfo() != null) {
            return mTabAllDataBean.getOuterVideoInfo();
        } else {
            return null;
        }
    }

    public RecAlbumBean getRecAlbumInfo() {
        if (mTabAllDataBean != null && mTabAllDataBean.getTabRelate() != null
                && mTabAllDataBean.getTabRelate().getTabIndicatorData() != null
                && mTabAllDataBean.getTabRelate().getTabIndicatorData().getVideoList().getRecAlbumInfo() != null) {
            return mTabAllDataBean.getTabRelate().getTabIndicatorData().getVideoList().getRecAlbumInfo();
        } else {
            return null;
        }
    }

    public void setVid(long vid) {

        this.vid = vid;
    }

    public long getVid() {
        if (vid > 0) {
            return vid;
        } 
        else if (videoBean != null) {
        	return videoBean.getVid();
        }
        else if (mTabAllDataBean != null && mTabAllDataBean.getVideoInfo() != null) {
            vid = mTabAllDataBean.getVideoInfo().getId();
            return vid;
        } else {
            return 0L;
        }
    }

    public int getCid() {
        if (cid > 0) {
            return (int) cid;
        }
        else if (videoBean != null) {
        	return videoBean.getCid();
        }
        else if (mTabAllDataBean != null && mTabAllDataBean.getVideoInfo() != null) {
            cid = mTabAllDataBean.getVideoInfo().getCid();
            return (int) cid;
        } else {
            return 0;
        }
    }

    public long getPid() {
        if (aid > 0) {
            return aid;
        }
        else if (videoBean != null) {
        	return videoBean.getPid();
        }
        else if (mTabAllDataBean != null && mTabAllDataBean.getVideoInfo() != null) {
            aid = mTabAllDataBean.getVideoInfo().getPid();
            return aid;
        } else {
            return 0L;
        }
    }

    public int getCurPage() {
        if (curPage > 0) {
            return curPage;
        } else if (mTabAllDataBean != null && mTabAllDataBean.getTabVideoList() != null
                && mTabAllDataBean.getTabVideoList().getTabIndicatorData() != null
                && mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList() != null) {
            curPage = Integer.valueOf(mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList()
                    .getPagenum());
            return curPage;
        } else {
            return 1;
        }
    }

    public int getEpisodeNum() {
        if (episodeNum > 0) {
            return episodeNum;
        } else if (mTabAllDataBean != null && mTabAllDataBean.getTabVideoList() != null
                && mTabAllDataBean.getTabVideoList().getTabIndicatorData() != null
                && mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList() != null) {
            episodeNum = Integer.valueOf(mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList()
                    .getEpisodeNum());
            return episodeNum;
        } else {
            return 1;
        }
    }

    public int getTotalNum() {
        if (totle > 0) {
            return totle;
        } else if (mTabAllDataBean != null && mTabAllDataBean.getTabVideoList() != null
                && mTabAllDataBean.getTabVideoList().getTabIndicatorData() != null
                && mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList() != null) {
            totle = Integer.valueOf(mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList()
                    .getTotalNum());
            return totle;
        } else {
            return 1;
        }
    }

    public boolean getIsShowPayGuide() {
        if (mTabAllDataBean != null && mTabAllDataBean.getVideoInfo() != null) {
            return (mTabAllDataBean.getVideoInfo().getPay() == 1 ? true : false) && isVideoNormal;
        } else {
            return false;
        }
    }

    /*
     * 根据视频信息获取tab签上显示文本
     */
    public int judgeVideoByVideoAlbum(VideoBean videoPlayerLibs, AlbumNew albumNewPlayerLibs) {

        if (videoPlayerLibs == null) {
            return 0;
        }
        if (albumNewPlayerLibs == null) {
            return 3;
        }

        int videoCid = videoPlayerLibs.getCid();
        long videoVid = videoPlayerLibs.getId();

        switch (videoCid) {
            case AlbumNew.Channel.TYPE_TVSHOW: // 综艺 正片显示剧情，按年月请求
                if (videoVid > 0) {
                    // 非正片不用显示剧情直接显示相关
                    if (videoPlayerLibs != null && !TextUtils.isEmpty(videoPlayerLibs.getVideoTypeKey())
                            && videoPlayerLibs.getVideoTypeKey().equals(VIDEONORMAL)) {
                        isShowMode = 1;
                    }
                } else {
                    if (albumNewPlayerLibs.getPlatformVideoInfo() > 0) {
                        isShowMode = 1;
                    }
                }
                break;
            case AlbumNew.Channel.TYPE_MUSIC: // 音乐 栏目类显示列表，按年月请求
                // 非栏目直接显示相关
                if (albumNewPlayerLibs.getVarietyShow() == 1) // 栏目
                {
                    isShowMode = 2;
                }
                break;
            case AlbumNew.Channel.TYPE_DOCUMENT_FILM: // 纪录片
                if (videoVid > 0 && videoPlayerLibs != null) {
                    if (VIDEONORMAL.equals(videoPlayerLibs.getVideoTypeKey())) {
                        if (albumNewPlayerLibs.getVarietyShow() == 1) {
                            isShowMode = 1;
                        } else {
                            isShowMode = 0;
                        }
                    }
                } else {
                    if (albumNewPlayerLibs.getVarietyShow() == 1) // 栏目
                    {
                        if (albumNewPlayerLibs.getPlatformVideoNum() > 0) {
                            isShowMode = 1;
                        }
                    } else { // 非栏目
                        if (albumNewPlayerLibs.getPlatformVideoInfo() > 0) {
                            isShowMode = 0;
                        }
                    }
                }
                break;
            case AlbumNew.Channel.TYPE_PE:
            case AlbumNew.Channel.TYPE_FINANCIAL: // 栏目按年月请求,非栏目直接显示相关,不请求列表
            case AlbumNew.Channel.TYPE_OPEN_CLASS: // 体育、财经、公开课：传入参数：videoType=0
                // 。（取正片，默认为正片）
                if (albumNewPlayerLibs.getVarietyShow() == 1) // 栏目
                {
                    if (VIDEONORMAL.equals(videoPlayerLibs.getVideoTypeKey())) {
                        isShowMode = 1;
                    } else {
                        isShowMode = 3;
                    }
                } else { // 非栏目
                    isShowMode = 3;
                }
                break;
            case AlbumNew.Channel.TYPE_JOY:
            case AlbumNew.Channel.TYPE_HOT:
            case AlbumNew.Channel.TYPE_FASHION:
            case AlbumNew.Channel.TYPE_TOURISM:
            case AlbumNew.Channel.TYPE_PATERNITY:
            case AlbumNew.Channel.TYPE_CAR:
            case AlbumNew.Channel.TYPE_NBA: // 栏目按年月请求,非栏目直接显示相关,不请求列表
                // 汽车、旅游、风尚、娱乐、热点、亲子6个频道：传入参数videoType=1.（取全部）
                if (albumNewPlayerLibs.getVarietyShow() == 1) // 栏目
                {
                    isShowMode = 1;
                }
                break;
            case AlbumNew.Channel.TYPE_TV:
            case AlbumNew.Channel.TYPE_MOVIE:
            case AlbumNew.Channel.TYPE_CARTOON:
                if (videoVid <= 0) {
                    if (albumNewPlayerLibs.getPlatformVideoInfo() > 0) {
                        isShowMode = 0;
                    }
                }
                break;
            default: // 其它频道 正常获取视频列表
                isShowMode = 0;
                break;
        }

        return isShowMode;
    }

    public void setVideoBean(VideoBean videoBean) {
        this.videoBean = videoBean;
    }
    
    public VideoBean getVideoBean() {
        return videoBean;
    }

    public AlbumNew getAlbum() {
        return album;
    }

    public void setAlbum(AlbumNew album) {
        this.album = album;
    }

    /**
     * 设置 Album 并且同步 其他数据信息
     *
     * @param album
     */
    public void setAlbumAndSysInfo(AlbumNew album) {
        if (null == album) {
            return;
        }
        setAlbum(album);
        merge = 0;
        order = getOrder(album.getCid());
        totle = merge == 0 ? album.getPlatformVideoInfo() : album.getPlatformVideoNum();// 合并与不合并总级数取不一样的字段
        isList = getIsList(album.getStyle());// 初始化，是宫格合适列表
        if (mActivity instanceof AlbumPlayActivity) {
            if (((AlbumPlayActivity) mActivity).getFlow() != null) {
                ((AlbumPlayActivity) mActivity).getFlow().setAlbum(album);
            }
        } else if(mActivity instanceof AlbumPlayRoomActivity) {
            if (((AlbumPlayRoomActivity) mActivity).getFlow() != null) {
                ((AlbumPlayRoomActivity) mActivity).getFlow().setAlbum(album);
            }
        }

    }

    /**
     * -1:按着集数升序; 1:按着集数降序.默认为:-1
     * 根据频道区分 列表是倒序还是正序 ,modified by zengsonghai 20140221
     * */
    public String getOrder(int cid) {
        return (cid == AlbumNew.Channel.TYPE_TVSHOW || cid == AlbumNew.Channel.TYPE_JOY || cid == AlbumNew.Channel.TYPE_PE) ? "1"
                : "-1";
    }

    /**
     * 根据style区分视频列表是否列表形势
     * */
    public boolean getIsList(String style) {
        return "1".equals(style) ? false : true;
    }

    // 获取FragmentManger防止出现Fragment嵌套情况
    public FragmentManager getChildFragmentManager() {
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        return fragmentManager;
    }

    public FragmentActivity getActivity() {
        return mActivity;
    }

    public boolean isEpisodeWatched() {
        return isEpisodeWatched;
    }

    public void setEpisodeWatched(boolean isEpisodeWatched) {
        LogInfo.log("hong6", "setEpisodeWatched from GridView");
        this.isEpisodeWatched = isEpisodeWatched;
    }

    /**
     * 播放 只针对本专辑下的视频
     */
    public void play(VideoBean tabVideoInfoBean) {
        videoBean = tabVideoInfoBean;
        vid = tabVideoInfoBean.getVid();
        aid = tabVideoInfoBean.getPid();
        cid = tabVideoInfoBean.getCid();

        if (mActivity instanceof AlbumPlayActivity) {
            if (((AlbumPlayActivity) mActivity).getFlow() != null) {
                ((AlbumPlayActivity) mActivity).getFlow().play(tabVideoInfoBean);
                hasNext();
            }
        } else if(mActivity instanceof AlbumPlayRoomActivity) {
            if (((AlbumPlayRoomActivity) mActivity).getFlow() != null) {
                ((AlbumPlayRoomActivity) mActivity).getFlow().play(tabVideoInfoBean);
                hasNext();
            }
        }
    }

    /**
     * 获取当前播放的视频所在位置
     * 
     * @return
     */
    public int getVideoIndex() {
        int index = 0;
        if (videos != null && videoBean != null) {
            VideoListBean list = videos.get(curPage);
            if (videos != null && list != null) {
                if (getVideoBean() != null && list.contains(getVideoBean())) {
                    index = list.indexOf(getVideoBean());
                } else {
                    int j = list.size();
                    for (int i = 0; i < j; i++) {
                        VideoBean mVideoPlayerLibs = list.get(i);
                        if (mVideoPlayerLibs != null && videoBean != null 
                                && mVideoPlayerLibs.getId() == videoBean.getId()) {
                            index = i;
                            break;
                        }
                    }
                }
            }
        }
        return index;
    }

    public boolean isDolby() {
        return mIsDolby;
    }

    public void setIsDolby(boolean mIsDolby) {
        this.mIsDolby = mIsDolby;
    }

    public boolean isShowToast() {
        return mIsShowToast;
    }

    public int getCurrentPlayStream() {
        return mCurrentPlayStream;
    }

    public void requestAlbumListInfo(int page,
            ExpandableListUpdateGroupNotByDateCallBack expandableListUpdateGroupNotByDateCallBack) {
        mExpandableListUpdateGroupNotByDateCallBack = expandableListUpdateGroupNotByDateCallBack;
        LogInfo.log("+-->", "---requestAlbumListInfo---");
        isRequestAlbumListByDate = false;
        curPage = page;

        requestAlbumListTask();
    }
    
    private void requestAlbumListTask() {
        if (requestAlbumListInfo == null) {
            requestAlbumListInfo = new RequestAlbumListInfo();
        }
        isRequestAlbumListByDate = false;
        boolean isPlay = false;
        if (vid > 0) {
            isPlay = true;
        }
        requestAlbumListInfo.setParams(isPlay, false, curPage, aid, vid);
        requestAlbumListInfo.start();
    }

    
    /**
     * 请求 动漫类分页剧集
     */
    private class RequestAlbumListInfo {

        private boolean isPlay;

        private int page;

        private String markId;

        private long videoId;

        private long albumId;

        private int localDataPos;

        private boolean isNextPlay;

        public void setParams(boolean isPlay, boolean isNextPlay, int page, long aid, long vid) {
            this.isPlay = isPlay;
            this.page = page;
            this.videoId = vid;
            this.albumId = aid;
            this.isNextPlay = isNextPlay;
        }

        public void start() {
            new LetvRequest<VideoListBean>(getActivity(), VideoListBean.class)
                    .setRequestType(RequestManner.CACHE_THEN_NETROWK)
                    .setUrl(MediaAssetApi.getInstance().getCombineDataVListUrl(mActivity,"", "", "", "", String.valueOf(albumId),
                            String.valueOf(page), String.valueOf(pageSize), "", ""))
                    .setCache(new VolleyDiskCache(getActivity()))
                    .setParser(new VideoListParser())
                    .setCallback(new SimpleResponse<VideoListBean>() {

                        @Override
                        public void onNetworkResponse(VolleyRequest<VideoListBean> request, VideoListBean result,
                                DataHull hull, NetworkResponseState state) {
                            if (state == NetworkResponseState.SUCCESS) {
                                albumListResponse(result);
                                if (mExpandableListUpdateGroupNotByDateCallBack != null) {
                                    mExpandableListUpdateGroupNotByDateCallBack.updateExpandList(curPage, curPage - 1,
                                        videos);
                                }
                            }
                        }

                        @Override
                        public void onCacheResponse(VolleyRequest<VideoListBean> request, VideoListBean result,
                                DataHull hull, CacheResponseState state) {
                            if (state == CacheResponseState.SUCCESS) {
                                albumListResponse(result);
                                if (mExpandableListUpdateGroupNotByDateCallBack != null) {
                                    mExpandableListUpdateGroupNotByDateCallBack.updateExpandList(curPage, curPage - 1,
                                        videos);
                                }
                            }
                        }

                        @Override
                        public void onErrorReport(VolleyRequest<VideoListBean> request, String errorInfo) {
                            super.onErrorReport(request, errorInfo);

                        }

                    }).add();
        }

        private void albumListResponse(VideoListBean result) {
            if (result != null) {
                VideoListBean videoListPlayerLibs = result;
                totalNum = result.getTotalNum();
                episodeNum = result.getEpisodeNum();
                // startRequestVideoByVid();

                if (null != videoListPlayerLibs) {
                    int p = result.getPagenum();
                    LogInfo.log("king", "onPostExecute isPlay = " + isPlay + " ,p = " + p);
                    curPage = page;
                    if (videoListPlayerLibs.size() > 0) {
                        videoBean = videoListPlayerLibs.get(0);
                    }

                    if (!isVideoNormal) {
                        if (videos != null) {
                            videos.clear();
                        }
                        if (mVideoListPlayerLibs != null) {
                            mVideoListPlayerLibs = null;
                        }
                    }
                    if(videoBean == null) {
                    	return;
                    }
                    vid = videoBean.getId();

                    LogInfo.log("Emerson", "-111-播放记录-TMD6--pid = "
                            + (playRecordPlayerLibs != null ? playRecordPlayerLibs.getAlbumId() : "1"));
                    // createPlayRecord(true);
                    if (playRecordPlayerLibs != null) {
                        playRecordPlayerLibs.setTotalDuration(videoBean.getDuration());
                        totleTime = playRecordPlayerLibs.getTotalDuration() * 1000;
                    }
                    if (isExpandListAndPlayFlag()) {
                        setExpandListAndPlayFlag(false);
                        notifyFlowPlayNext(videoBean);
                    }
                    LogInfo.log("onPostExecute curPage =" + curPage + "  page =" + page);
                    if (videos != null && videoListPlayerLibs != null) {
                        videos.put(curPage, videoListPlayerLibs);
                    }
                } else {
                	
                }
            }
        }
    }

    /**
     * 按年月请求视频列表数据 分页请求需要回调
     * */
    public void requestAlbumListByDate(String year, String month, long aid, long vid,
            ExpandableListUpdateGroupCallBack expandableListUpdateGroupCallBack) {
        this.year = year;
        this.month = month;
        this.mExpandableListUpdateGroupCallBack = expandableListUpdateGroupCallBack;

        isRequestAlbumListByDate = true;
        boolean isPlay = false;
        if (vid <= 0) {
            isPlay = true;
        }
        requestAlbumListInfoByDateTask(isPlay, year, month, aid, vid);
    }

    private void requestAlbumListInfoByDateTask(boolean isPlay, String year, String month, long aid, long vid) {
        if (requestAlbumListInfoByDate == null) {
            requestAlbumListInfoByDate = new RequestAlbumListInfoByDate();
        }
        requestAlbumListInfoByDate.setParams(isPlay, false, year, month, aid, vid);
        requestAlbumListInfoByDate.start();
    }

    /**
     * 请求专辑详情和专辑视频列表（某些频道的栏目类型的需要此接口请求 例如 综艺）
     */
    private class RequestAlbumListInfoByDate {

        private String markId;

        private long videoId;

        private long albumId;

        private boolean isPlay;

        private boolean isNextPlay;

        private String year;

        private String month;

        private boolean isVideoNotifyed = false;

        private boolean isRequestVideoPlayCount = false;

        public RequestAlbumListInfoByDate() {

        }

        public RequestAlbumListInfoByDate(boolean isPlay, boolean isNextPlay, String year, String month, long aid,
                long vid) {
            this.year = year;
            this.month = month;
            this.videoId = vid;
            this.albumId = aid;
            this.isPlay = isPlay;
            this.isNextPlay = isNextPlay;
        }

        public void setParams(boolean isPlay, boolean isNextPlay, String year, String month, long aid, long vid) {
            this.year = year;
            this.month = month;
            this.videoId = vid;
            this.albumId = aid;
            this.isPlay = isPlay;
            this.isNextPlay = isNextPlay;
        }

        public void start() {
            new LetvRequest<AlbumNewListByDateBean>(getActivity(), AlbumNewListByDateBean.class)
                    .setRequestType(RequestManner.CACHE_THEN_NETROWK)
                    .setUrl(MediaAssetApi.getInstance().getCombineDataVListUrl(mActivity,"", "", "", "", String.valueOf(albumId),
                            "", "", year, month)).setCache(new VolleyDiskCache(getActivity()))
                    .setParser(new AlbumNewListByDateParser())
                    .setCallback(new SimpleResponse<AlbumNewListByDateBean>() {

                        @Override
                        public void onNetworkResponse(VolleyRequest<AlbumNewListByDateBean> request,
                                AlbumNewListByDateBean result, DataHull hull, NetworkResponseState state) {
                            if (state == NetworkResponseState.SUCCESS) {
                            	if(mExpandableListUpdateGroupCallBack !=null){
                            		mExpandableListUpdateGroupCallBack.updateExpandList(result);
                            	}
                                albumListByDateResponse(result);
                            }
                        }

                        @Override
                        public void onCacheResponse(VolleyRequest<AlbumNewListByDateBean> request,
                                AlbumNewListByDateBean result, DataHull hull, CacheResponseState state) {
                            if (state == CacheResponseState.SUCCESS) {
                            	if(mExpandableListUpdateGroupCallBack !=null){
                            		mExpandableListUpdateGroupCallBack.updateExpandList(result);
                            	}
                                albumListByDateResponse(result);
                            }
                        }

                        @Override
                        public void onErrorReport(VolleyRequest<AlbumNewListByDateBean> request, String errorInfo) {
                            super.onErrorReport(request, errorInfo);

                        }

                    }).add();
        }
        private void albumListByDateResponse(AlbumNewListByDateBean result) {
            LogInfo.log("carey", "RequestAlbumListInfoByDate: onPostExecute " + (result == null));
            if (result != null && result.getYearList().size() > 0) {
                AlbumNewListByDateBean tempAlbumNewListByDatePlayerLibs = result;
                if (albumNewListByDatePlayerLibs == null) {
                    albumNewListByDatePlayerLibs = tempAlbumNewListByDatePlayerLibs;
                } else {   	
                    if (albumNewListByDatePlayerLibs.getYearList() != null
                            && albumNewListByDatePlayerLibs.getYearList().get(year) != null
                            && albumNewListByDatePlayerLibs.getYearList().get(year).get(month) != null
                            && albumNewListByDatePlayerLibs.getYearList().get(year).get(month).size() == 0) {
                        if (tempAlbumNewListByDatePlayerLibs != null 
                                && tempAlbumNewListByDatePlayerLibs.getYearList() != null
                                && tempAlbumNewListByDatePlayerLibs.getYearList().get(year) != null
                                && tempAlbumNewListByDatePlayerLibs.getYearList().get(year).get(month) != null)
                        albumNewListByDatePlayerLibs.getYearList().get(year).get(month)
                                .addAll(tempAlbumNewListByDatePlayerLibs.getYearList().get(year).get(month));
                    }
                }

                if (mExpandableListUpdateGroupCallBack != null) {
                    mExpandableListUpdateGroupCallBack.updateExpandList(tempAlbumNewListByDatePlayerLibs);
                }

                if (mExpandableListUpdateGroupCallBack == null) {
                    LogInfo.log("king", "onPostExecute notifyViewPageData");
                    LogInfo.log("hong", "---downloadCallBack()---");
                    videosCallBackState = PlayAlbumControllerCallBack.STATE_FINISH;

                }
                if (isPlay) {
                    LinkedHashMap<String, AlbumNewListByDateBean.MonthList> yearList = result.getYearList();
                    if (yearList != null && yearList.size() > 0) {
                        Iterator<String> its = yearList.keySet().iterator();
                        while (its.hasNext()) {
                            AlbumNewListByDateBean.MonthList monthList = yearList.get(its.next());
                            if (monthList != null && monthList.size() > 0) {
                                Iterator<String> monthIts = monthList.keySet().iterator();
                                while (monthIts.hasNext()) {
                                    ArrayList<VideoBean> videoList = monthList.get(monthIts.next());
                                    if (videoList != null && videoList.size() > 0) {
                                        // setVideoBean(videoList.get(0));
                                        vid = videoBean.getId();
                                        cid = videoBean.getCid();

                                        videosCallBackState = PlayAlbumControllerCallBack.STATE_NEXT;
                                        if (videosCallBack != null) {
                                            videosCallBack.notify(PlayAlbumControllerCallBack.STATE_NEXT);
                                        }

                                        LogInfo.log("Emerson", "-111-播放记录-TMD8--pid = "
                                                + (playRecordPlayerLibs != null ? playRecordPlayerLibs.getAlbumId() : "1"));
                                        // createPlayRecord(true);
                                        if (playRecordPlayerLibs != null) {
                                            playRecordPlayerLibs.setTotalDuration(videoBean.getDuration());
                                            totleTime = playRecordPlayerLibs.getTotalDuration() * 1000;
                                        }
                                        if (album != null && album.canPlay()) {
                                        	
                                        	play(videoList.get(0));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                hasNext();
            } 
        }

    }

    private boolean isLastInAlbumList() {
        boolean isLastInList = false;   // 是否为albumList中的最后一项
        ArrayList<AlbumNew> albumNewList = getTabAlbumList();        
        if (albumNewList != null && albumNewList.size() > 0) {
            int nSize = albumNewList.size();            
            for (int k = 0; k < nSize; k++) {
                if (albumNewList.get(k) != null && aid == albumNewList.get(k).getAid()) {
                    if (k == nSize - 1) {
                        isLastInList = true;
                    }
                    break;
                }
            }            
        }
        else {
            isLastInList = true;
        }
        return isLastInList;
    }
    
    /*
     * 非正片两栏专题数据
     */
    private boolean isLastInNonNormalAlbumList() {
        boolean isLastInList = false;   // 是否为专题非正片中的最后一项
        if (!isVideoNormal && !isPlayFromAlbumFlag()) {
            int page = -1;
            Iterator<Integer> ir = videos.keySet().iterator();
            while (ir.hasNext()) {
                page = ir.next();
                LogInfo.log("king", "hasNext page = " + page);
                VideoListBean list = videos.get(page);
                if (list != null) {
                    int nSize = list.size();
                    if (nSize > 0 && videoBean != null) {
                        for (int i = 0; i < nSize; i++) {
                            if (list.get(i) != null && videoBean.getId() == list.get(i).getId()) {
                                if (i == nSize - 1) {
                                    isLastInList = true;
                                }
                                break;
                            }
                        }
                        if (isLastInList) {
                            break;
                        }
                    }
                }
            }
        }
        
        return isLastInList;
    }
    
    /**
     * 判断是否有下一集
     */
    private void hasNext() {

        if (isFromWorldCupDownload) {
            return;
        }
        if (!isRequestAlbumListByDate || albumNewListByDatePlayerLibs == null) {
            boolean isLastInListFlag = false;
            int pos = -1;
            int page = -1;
            LogInfo.log("king", "hasNext isVideoNormal = " + isVideoNormal);
            /*
             * 正片数据
             */
            if (videos != null && videos.size() > 0) {
                Iterator<Integer> ir = videos.keySet().iterator();
                while (ir.hasNext()) {
                    page = ir.next();
                    LogInfo.log("king", "hasNext page = " + page);
                    VideoListBean list = videos.get(page);
                    int nSize = list.size();
                    if (list != null && nSize > 0 && videoBean != null) {
                        for (int i = 0; i < nSize; i++) {
                            if (list.get(i) != null && videoBean.getId() == list.get(i).getId()) {
                                if (i == nSize - 1) {
                                    isLastInListFlag = true;
                                }
                                pos = i;
                                break;
                            }
                        }
                        
                        /*
                         * Added by chenhong 2015-07-26, for play record next episode
                         */
                        if (pos >= 0 && pos < list.size() - 1 && list.get(pos + 1) != null 
                                && list.get(pos + 1).getVideoTypeKey().endsWith(VIDEONORMAL)) {                            
                            playRecordNextVid = list.get(pos + 1).getId();
                        }
                        else {
                            playRecordNextVid = 0L;
                        }
                        
                        if (pos != -1 && page != -1) {
                            break;
                        }
                    }
                }
            }
            /*
             * 推荐数据
             */
            else if (mRecommendInfoListPlayerLibs != null && videoBean != null) {
                for (int i = 0, nSize = mRecommendInfoListPlayerLibs.size(); i < nSize; i++) {
                    
                    if (mRecommendInfoListPlayerLibs.get(i) !=null && mRecommendInfoListPlayerLibs.get(i).id == videoBean.getId()) {
                        if (i == nSize - 1) {
                            isLastInListFlag = true;
                        }
                        pos = i;
                        break;
                    }
                }
            }            

            LogInfo.log("king", "====hasNext, pos:" + pos + ";==page:" + page + "; total=" + totle);
            if (!isVideoInPlayRecommend()) {
                videoRecommendList = null;
                setVideoRecommend(null);
            }

            // 视频是正片，在当前列表中不存在，或者为最后一个视频
            boolean isLastInNormalVideosFlag = ((pos == -1 || (pageSize * (page - 1) + pos + 1) == totle) && totle > 0) 
                    || (isLastInListFlag && totle == 0);
            //(isVideoNormal && (pos == -1 || (pageSize * (page - 1) + pos + 1) == totle) && totle > 0);
            // 推荐视频为空 或者 当推荐视频不为空而且处于最后一个位置时
            boolean isLastInRelateVideosFlag = (mRecommendInfoListPlayerLibs != null && (pos == mRecommendInfoListPlayerLibs.size() - 1));
            // 是否为第二栏专题视频列表中的最后一项
            boolean isLastInAlbumThreeListFlag = isLastInAlbumList();
            // 是否为专题两栏非正片的最后一项
            boolean isLastInNonNormalTwoListFlag = isLastInNonNormalAlbumList();
            
            if (videoRecommendList == null 
                    && ((isLastInNormalVideosFlag && isLastInAlbumThreeListFlag) 
                    || isLastInRelateVideosFlag || isLastInNonNormalTwoListFlag)) {
                // 请求连播数据
                requestPlayRecommendTask();
            }
            else {
                videoRecommendList = null;
                setVideoRecommend(null);
            }
        } else {
            boolean isYearKeyLast = false;
            boolean isMonthKeyLast = false;
            boolean isFind = false;
            boolean isLastVideo = false;
            if (albumNewListByDatePlayerLibs != null && albumNewListByDatePlayerLibs.getYearList() != null
                    && albumNewListByDatePlayerLibs.getYearList().size() != 0) {
                LinkedHashMap<String, AlbumNewListByDateBean.MonthList> yearList = albumNewListByDatePlayerLibs
                        .getYearList();
                Iterator<String> yearKeys = yearList.keySet().iterator();
                String yearKey = "";
                String monthKey = "";
                while (yearKeys.hasNext()) {
                    yearKey = yearKeys.next();
                    AlbumNewListByDateBean.MonthList monthList = yearList.get(yearKey);
                    if (monthList != null && monthList.size() > 0) {
                        Iterator<String> monthKeys = monthList.keySet().iterator();
                        while (monthKeys.hasNext()) {
                            monthKey = monthKeys.next();
                            ArrayList<VideoBean> videoList = monthList.get(monthKey);
                            if (videoList != null && videoList.size() > 0) {
                                int size = videoList.size();
                                int pos = -1;
                                for (int i = 0; i < size; i++) {
                                    if (videoBean != null && videoList.get(i) != null && videoBean.getId() == videoList.get(i).getId()) {
                                        pos = i;
                                        isFind = true;
                                        break;
                                    }
                                }
                                
                                /*
                                 * Added by chenhong 2015-07-26, for play record next episode
                                 */
                                if (pos >= 0 && pos < videoList.size() - 1 && videoList.get(pos + 1) != null) {
                                    playRecordNextVid = videoList.get(pos + 1).getId();
                                }
                                else {
                                    playRecordNextVid = 0L;
                                }
                                
                                if (isFind) {
                                    if (pos == size - 1) { // 本期最后一个视频，需要播下一期第一个视频
                                        isLastVideo = true;
                                    }
                                }
                            }
                            isMonthKeyLast = !monthKeys.hasNext();
                            if (isFind) {
                                break;
                            }
                        }
                    }
                    isYearKeyLast = !yearKeys.hasNext();
                    if (isFind) {
                        break;
                    }
                }
            }
            if (!isVideoInPlayRecommend()) {
                videoRecommendList = null;
                setVideoRecommend(null);
            }
            if ((!isFind || (isFind && isYearKeyLast && isMonthKeyLast && isLastVideo)) && videoRecommendList == null) {
                // 请求连播数据
                requestPlayRecommendTask();
                // new RequestPlayRecommend(getActivity()).start();
            }
        }
    }

    private void requestPlayRecommendTask() {
        if (requestPlayRecommend == null) {
            requestPlayRecommend = new RequestPlayRecommend();
        }
        isRequestAlbumListByDate = false;
        requestPlayRecommend.start();
    }

    /**
     * 请求连播数据
     */
    private class RequestPlayRecommend {
        public void start() {
            new LetvRequest<HomePageBean>(getActivity(), HomePageBean.class)
                    .setRequestType(RequestManner.CACHE_THEN_NETROWK)
                    .setCache(new VolleyDiskCache(getActivity(), "RequestPlayRecommend_" + cid + aid + vid))
                    .setParser(new HomePageBeanParser()).setCallback(new SimpleResponse<HomePageBean>() {

                        @Override
                        public void onNetworkResponse(VolleyRequest<HomePageBean> request, HomePageBean result,
                                DataHull hull, NetworkResponseState state) {
                            if (state == NetworkResponseState.SUCCESS) {
                                playRecommendResponse(result);
                            }
                            else if (state == NetworkResponseState.NETWORK_NOT_AVAILABLE) {
                                if (videoRecommendList == null || videoRecommendList.size() == 0) {
                                    finishPlayer();
                                }
                            }
                        }

                        @Override
                        public void onCacheResponse(VolleyRequest<HomePageBean> request, HomePageBean result,
                                DataHull hull, CacheResponseState state) {                            
                            if (state == CacheResponseState.SUCCESS) {
                                playRecommendResponse(result);
                            }
                            request.setUrl(MediaAssetApi.getInstance().getRequestPlayRecommendurl(mActivity,hull.getMarkId(),
                                    String.valueOf(cid), String.valueOf(aid), String.valueOf(vid)));
                        }

                        @Override
                        public void onErrorReport(VolleyRequest<HomePageBean> request, String errorInfo) {
                            super.onErrorReport(request, errorInfo);
                        }

                    }).add();
        }

        private void playRecommendResponse(HomePageBean result) {
            if (result != null) {
                if (result.getBlock() != null && result.getBlock().size() > 0) {
                    HomeBlock block = result.getBlock().get(0);
                    if (block != null && !BaseTypeUtils.isListEmpty(block.getList())) {
                        videoRecommendList = new ArrayList<HomeMetaData>();
                        videoRecommendList.addAll(block.getList());
                        setVideoRecommend(videoRecommendList.get(0));
                        videoRecommendIndex = 0;
                     
                        /*
                         * Added by chenhong 2015-07-26, for play record next episode
                         * Commented, product manager requirement, not continue to play when play to 
                         * the end of the video list
                         */
//                        playRecordNextVid = videoRecommendList.get(0).getVid();
                    }
                }
            }
        }
    }

    @Override
    public void onNetworkResponse(VolleyRequest<? extends LetvBaseBean> request, LetvBaseBean result, DataHull hull,
            NetworkResponseState state) {

        if (result instanceof TabAllDataBean) {
        	mPlayFromAlbumFlag = true;
            mTabAllDataBean = (TabAllDataBean) result;
            parseEpisodeData(mTabAllDataBean);
        }
        /*
         *  解析初次返回的Tabs数据
         */
        else if (result instanceof TabTopicAllDataBean) {   
        	mPlayFromAlbumFlag = false;
            mTabTopicAllDataBean = (TabTopicAllDataBean) result;
            parseTopicEpisodeData(mTabTopicAllDataBean);
        }
        /*
         * 解析点击专题列表放回的Vlist数据
         */
        else if (result instanceof TabTopicVideoListBean) {
        	mPlayFromAlbumFlag = false;
            mTabTopicVideoListBean = (TabTopicVideoListBean) result;
            parseTopicVideoListData(mTabTopicVideoListBean);
        }
        if(state != NetworkResponseState.SUCCESS){
            isNetSuccess = false;
        	if(fullRefesh != null){
    			fullRefesh.refreshDataForFull(false);
    		}
        }else{
            isNetSuccess = true;
        	if(fullRefesh != null){
    			fullRefesh.refreshDataForFull(true);
    		}
        }
        hasNext();
    }

    @Override
    public void onCacheResponse(VolleyRequest<? extends LetvBaseBean> request, LetvBaseBean result, DataHull hull,
            CacheResponseState state) {
    	
        if (result instanceof TabAllDataBean) {
        	mPlayFromAlbumFlag = true;
            mTabAllDataBean = (TabAllDataBean) result;
            parseEpisodeData(mTabAllDataBean);
        }
        else if (result instanceof TabTopicAllDataBean) {
        	mPlayFromAlbumFlag = false;
            mTabTopicAllDataBean = (TabTopicAllDataBean) result;
            parseTopicEpisodeData(mTabTopicAllDataBean);            
        }
        else if (result instanceof TabTopicVideoListBean) {
        	mPlayFromAlbumFlag = false;
            mTabTopicVideoListBean = (TabTopicVideoListBean) result;
            parseTopicVideoListData(mTabTopicVideoListBean);
        }
        isCacheSuccess = state == CacheResponseState.SUCCESS;

    }

    @Override
    public void onErrorReport(VolleyRequest<? extends LetvBaseBean> request, String errorInfo) {
        
    }

    protected void setRedirectArguments() {
        Intent intent = getActivity().getIntent();
        from = intent.getIntExtra("from", PlayConstant.LAUNCH_FROM_CHANNEL);
        mBackWhere = intent.getBooleanExtra("back", false);
        if (from == PlayConstant.LAUNCH_FROM_RECOMMEND) {
            videoRecommendList = (ArrayList<HomeMetaData>) intent.getSerializableExtra("videoList");
            videoRecommendIndex = intent.getIntExtra("recommendIndex", videoRecommendIndex) + 1;
            if (isVideoRecommendIndexValid()) {
                setVideoRecommend(videoRecommendList.get(videoRecommendIndex));
            }
        } else if (from == PlayConstant.LAUNCH_FROM_SCANQRCODE) {
            htime = intent.getLongExtra("htime", 0);
        } else if (from == PlayConstant.LAUNCH_FROM_DOWNLOAD_WORLDCUP) {
            // 2014-07-11 ljnalex delete v5.4.3 start 口袋看球需求变更
            // 2014-08-19 ljnalex recover v5.4.6 start 口袋看球需求恢复
            isFromWorldCupDownload = true;
            // 2014-08-19 ljnalex recover v5.4.6 end
            // 2014-07-11 ljnalex delete v5.4.3 end
        }
        int launchMode = 0;
        if(mActivity instanceof AlbumPlayActivity) {
            launchMode = ((AlbumPlayActivity) getActivity()).getFlow().getLaunchMode();
        } else if(mActivity instanceof AlbumPlayRoomActivity) {
            launchMode = ((AlbumPlayRoomActivity) getActivity()).getFlow().getLaunchMode();
        }
        if (launchMode == PlayConstant.PLAY_ALBUM) {
            aid = intent.getIntExtra("aid", 0);
            if (aid < 0) {
                aid = 0;
            }
            vid = intent.getIntExtra("vid", 0);
            if (vid < 0) {
                vid = 0;
            }
            isDolby = intent.getBooleanExtra("isDolby", false);
            seek = intent.getLongExtra("seek", 0);
        } else if (launchMode == PlayConstant.PLAY_VIDEO) {
            vid = intent.getIntExtra("vid", 0);
            if (vid < 0) {
                vid = 0;
            }
            isDolby = intent.getBooleanExtra("isDolby", false);
            // zhudeshuai:添加对leso的判断
            if (isDolby || from == PlayConstant.LAUNCH_FROM_MSITE) {
                aid = intent.getIntExtra("aid", 0);
            }
            seek = intent.getLongExtra("seek", 0);
        } else if (launchMode == PlayConstant.PLAY_DOWNLOAD) {
            aid = intent.getIntExtra("aid", 0);
            if (aid < 0) {
                aid = 0;
            }
            vid = intent.getIntExtra("vid", 0);
            if (vid < 0) {
                vid = 0;
            }
            isDolby = intent.getBooleanExtra("isDolby", false);
            seek = intent.getLongExtra("seek", 0);
            // 2014-07-11 ljnalex delete v5.4.3 start 口袋看球需求变更
            /*
             * if (DBManager.getInstance().getWorldCupTrace().has(vid) != null)
             * { isFromWorldCupDownload = true; }
             */
            // 2014-07-11 ljnalex delete v5.4.3 end
        } else {
            // 获取SD卡文件的路径
            realUrl = intent.getStringExtra("uri");
            // wait to uncomment, need dlna redirection support
            // dlna.playUrl = realUrl;
            seek = intent.getLongExtra("seek", 0);
        }

    }

    private boolean isVideoInPlayRecommend() {
        if (videoRecommendList != null && videoRecommendList.size() > 0) {
            for (int i = 0; i < videoRecommendList.size(); i++) {
                LogInfo.log("isVideoInPlayRecommend -----video.getId()" + videoBean.getId()
                        + "----videoRecommendList.getVid:" + videoRecommendList.get(i).getVid());
                if (videoBean != null && videoRecommendList.get(i) != null 
                        && videoBean.getId() == videoRecommendList.get(i).getVid()) {
                    return true;
                }
            }
        }

        return false;
    }

    private boolean isVideoRecommendIndexValid() {
        return videoRecommendList != null && videoRecommendList.size() > 0 ? (videoRecommendIndex < videoRecommendList
                .size()) : false;
    }

    public DownloadDBListBean getmDownloadDBListBean() {
        return mDownloadDBListBean;
    }

    public void setmDownloadDBBeanListBean(DownloadDBListBean downloadDBListBean) {
        this.mDownloadDBListBean = downloadDBListBean;
    }   

    public void playVideoRecommend() {
        if (videoRecommendList != null && videoRecommendList.size() > 0) {
            HomeMetaData metaData = videoRecommendList.get(videoRecommendIndex);
            if (metaData != null) {
                if (videoRecommendIndex == 0) {
                    AlbumLaunchUtils.launch(getActivity(), metaData.getPid(), metaData.getVid(),
                            PlayConstant.LAUNCH_FROM_RECOMMEND, videoRecommendList, videoRecommendIndex);
                }
                else {
                    int nSize = videoRecommendList.size();
                    boolean isLastInRecomList = false;
                    for (int i = 0; i < nSize; i++) {
                        if (videoRecommendList.get(i).getId().equals(vid + "")) {
                            if (i == nSize - 1) {
                                isLastInRecomList = true;
                            }
                            else {
                                String strVid = videoRecommendList.get(i + 1).getId();
                                if (!TextUtils.isEmpty(strVid) && TextUtils.isDigitsOnly(strVid)) {
                                    vid = Long.valueOf(videoRecommendList.get(i + 1).getId());
                                }
                                else {
                                    vid = -1;
                                }
                            }
                            break;
                        }
                    }
                    if (!isLastInRecomList) {
                        if (vid > 0) {
                            notifyFlowPlayNext(vid);
                        }
                        else {
                            playVideoRecommend();
                        }
                    } 
                    else {
                        playVideoRecommend();
                    }
                }
            } else {
                requestPlayRecommendTask();
            }
        } else {
            requestPlayRecommendTask();
        }
    }

    private void finishPlayer() {
        if (mActivity instanceof AlbumPlayActivity) {
            ((AlbumPlayActivity) mActivity).getController().finishPlayer(isJumpToPip);
        } else if(mActivity instanceof AlbumPlayRoomActivity) {
            ((AlbumPlayRoomActivity) mActivity).getController().finishPlayer(isJumpToPip);
        }
    }

    private boolean videoRecommend() {
        if (!isPlayListLastVideo && from != PlayConstant.LAUNCH_FROM_RECOMMEND) {
            return false;
        }
        if (videoRecommendList == null || videoRecommendList.size() == 0) {
            return false;
        }
        if (isVideoInPlayRecommend()) {
            // 连播进行中
            if (!isVideoRecommendIndexValid()) {
                finishPlayer();
            } else {
                playVideoRecommend();

                relatedCallBackState = PlayAlbumControllerCallBack.STATE_NEXT;
                if (relatedCallBack != null) {
                    relatedCallBack.notify(PlayAlbumControllerCallBack.STATE_NEXT);
                }

                LogInfo.log("hong", "album video play in videoRecommend....");
                return true;
            }
        }

        return false;
    }

    public void playNext(){
 //        取消播放下一集  by pangzhen
        finishPlayer();
    }
    /**
     * 播放 播放下一集
     * */
//	public void playNext() {
//
//        /**
//         * v5.4.1 增加口袋看球（下载数据） 播完后不连播的需求
//         */
//        if (isFromWorldCupDownload) {
//            LogInfo.log("king", "isFromWorldCupDownload finishPlayer");
//            finishPlayer();
//            return;
//        }
//
//        /**
//         * 从二维码扫描进入，播放下一集清除from
//         */
//        if (from == PlayConstant.LAUNCH_FROM_SCANQRCODE) {
//            from = PlayConstant.LAUNCH_FROM_CHANNEL;
//        }
//
//        /*
//         * 续播，更新简介评论页面
//         */
//        isRefreshRelateDataAfterRequestPlayUrl = true;
//
//        LogInfo.log("hong", "---videos" + ((videos != null) && (videos.size() > 0)) + isRequestAlbumListByDate);
//
//        if (!isVideoNormal && mRecommendInfoListPlayerLibs != null && mRecommendInfoListPlayerLibs.size() > 0) {
//            playNextRelate(); // 播相关里的视频
//
//            /*
//             * 相关视频显示
//             */
//            if (relatedCallBack != null) {
//                relatedCallBackState = PlayAlbumControllerCallBack.STATE_NEXT;
//                relatedCallBack.notify(PlayAlbumControllerCallBack.STATE_NEXT);
//            }
//        }
//        else if (!isRequestAlbumListByDate && videos != null && videos.size() > 0) { // isVideoNormal &&  正常请求视频列表数据
//            playNextNormal();
//
//            /*
//             * 刷新剧集显示
//             */
//            if (videosCallBack != null) {
//                videosCallBackState = PlayAlbumControllerCallBack.STATE_NEXT;
//                videosCallBack.notify(PlayAlbumControllerCallBack.STATE_NEXT);
//            }
//        }
//        else if (albumNewListByDatePlayerLibs != null) {  // 按年月请求视频列表数据
//            playNextByDate();
//
//            /*
//             * 刷新剧集显示
//             */
//            if (videosCallBack != null) {
//                videosCallBackState = PlayAlbumControllerCallBack.STATE_NEXT;
//                videosCallBack.notify(PlayAlbumControllerCallBack.STATE_NEXT);
//            }
//        }
//        /*
//         * 专辑两栏专题情况下的续播处理逻辑
//         */
//        else if (!isVideoNormal && !isPlayFromAlbumFlag()) {
//            playNextNonNormalAlbumList();
//
//            /*
//             * 刷新剧集显示
//             */
//            if (videosCallBack != null) {
//                videosCallBackState = PlayAlbumControllerCallBack.STATE_NEXT;
//                videosCallBack.notify(PlayAlbumControllerCallBack.STATE_NEXT);
//            }
//        }
//        else {
//            playNextRelate(); // 播相关里的视频
//
//            /*
//             * 相关视频显示
//             */
//            if (relatedCallBack != null) {
//                relatedCallBackState = PlayAlbumControllerCallBack.STATE_NEXT;
//                relatedCallBack.notify(PlayAlbumControllerCallBack.STATE_NEXT);
//            }
//        }
//
//    }

    private void playNextRelate() {
        if (mRecommendInfoListPlayerLibs != null) {
            RecommendInfoListBean recomList = mRecommendInfoListPlayerLibs;
            int nSize = recomList.size();
            boolean isLastInRecomList = false;
            boolean isFindInList = false;
            int nIndex = 0;
            for (int i = 0; i < nSize; i++) {
                if (recomList.get(i) != null && recomList.get(i).id == vid) {
                    if (i == nSize - 1) {
                        isLastInRecomList = true;
                    }
                    else {
                        vid = recomList.get(i + 1).id;
                        /*
                         * 兼容返回
                         */
                        if (vid == 0) {
                        	nIndex = i;
                        }
                    }
                    isFindInList = true;
                    break;
                }
            }
    
            if (!isLastInRecomList && isFindInList) {
            	if (vid > 0) {
            		notifyFlowPlayNext(vid);
            	}
            	else {
            		AlbumLaunchUtils.launch(getActivity(), recomList.get(nIndex + 1).pid, 0,
                            PlayConstant.LAUNCH_FROM_PLAYRECORD, true);
            	}
            } 
            else {
               // playVideoRecommend();
                finishPlayer();
            }
        }
        else {
            playVideoRecommend();
        }            
    }
    
    /*
     * 专辑两栏情况下的续播处理逻辑
     */
    private void playNextNonNormalAlbumList() {        
        if (!isVideoNormal && !isPlayFromAlbumFlag()) {
            int page = -1;
            boolean isLastInList = false;
            boolean isFindInList = false;
            Iterator<Integer> ir = videos.keySet().iterator();
            while (ir.hasNext()) {
                page = ir.next();
                LogInfo.log("king", "hasNext page = " + page);
                VideoListBean list = videos.get(page);
                int nSize = list.size();
                if (list != null && nSize > 0) {
                    for (int i = 0; i < nSize; i++) {
                        if (list.get(i) != null && videoBean.getId() == list.get(i).getId()) {
                            if (i == nSize - 1) {
                                isLastInList = true;
                            }
                            else {
                                vid = list.get(i + 1).getId();
                            }
                            isFindInList = true;
                            break;
                        }
                    }
                }
            }
            
            if (!isLastInList && isFindInList) {
                notifyFlowPlayNext(vid);
            } 
            else {
                playVideoRecommend();
            }
        }
        else {
            playVideoRecommend();
        }
    }

    private void notifyFlowPlayNext(VideoBean video) {
        if (mActivity instanceof AlbumPlayActivity) {
            ((AlbumPlayActivity) mActivity).getFlow().playNext(video);
        } else if(mActivity instanceof AlbumPlayRoomActivity) {
            ((AlbumPlayRoomActivity) mActivity).getFlow().playNext(video);
        }
    }

    private void notifyFlowPlayNext(long vId) {
        if (mActivity instanceof AlbumPlayActivity) {
            ((AlbumPlayActivity) mActivity).getFlow().playNext(vId);
        } else if(mActivity instanceof AlbumPlayRoomActivity) {
            ((AlbumPlayRoomActivity) mActivity).getFlow().playNext(vId);
        }
    }

    /**
     * 一般视频的续播策略
     * */
    public void playNextNormal() {        
        LogInfo.log("hong12", Log.getStackTraceString(new Throwable()));
        boolean lastPlayIsLocalFile = isLocalFile;
        VideoBean v = videoBean;
        LogInfo.log("hong", "---playNextNormal() videoBean.getId()---" + videoBean.getId()
                + videoBean.getNameCn());
        LogInfo.log("hong", "---videoBean.getSubTitle--" + videoBean.getSubTitle());
        if (videos != null && videos.size() > 0) {
            isLocalFile = false;
            filePath = null;
            Iterator<Integer> ir = videos.keySet().iterator();
            int pos = -1;
            int page = -1;
            while (ir.hasNext()) {
                page = ir.next();
                VideoListBean list = videos.get(page);
                if (list != null && list.size() > 0) {
                    for (int i = 0; i < list.size(); i++) {
                        if (list.get(i) != null && v.getId() == list.get(i).getId()) {
                            pos = i;
                            break;
                        }
                    }
                    if (pos != -1 && page != -1) {
                        break;
                    }
                }
            }
            LogInfo.log("king", "playNext====playNext, pos:" + pos + ", page:" + page + ", total:" + totle);
            if (pos == -1 || page == -1) {
                if (videoRecommendList != null && videoRecommendList.size() > 0) {
                    LogInfo.log("king", "albume pos == -1 || page == -1");
                    playVideoRecommend();
                } else {
                    finishPlayer();
                }
                return;
            } else {
                isPlayNext = true;
                VideoListBean videoListPlayerLibs = videos.get(page);
                if (pos < videoListPlayerLibs.size() - 1) {

                    VideoBean videoPlayerLibsTmp = videoListPlayerLibs.get(pos + 1);
                    LogInfo.log("hong", "---playNextNormal()---" + pos + ";;;" + videoPlayerLibsTmp.getId()
                            + videoPlayerLibsTmp.getSubTitle() + videoPlayerLibsTmp.getNameCn());
                    if (LetvUtils.isInFinish(videoPlayerLibsTmp.getId())) {

                        LogInfo.log("hong", "playNext------0");
                        play(videoPlayerLibsTmp);
                    } else {

                        if (lastPlayIsLocalFile && !NetworkUtils.isNetworkAvailable(mActivity)) {// 如果播放下一集之前没有网络则播放下一个已下载的视频

                            LogInfo.log("hong", "playNext------1");
                            if(mActivity instanceof AlbumPlayActivity) {
                                if (((AlbumPlayActivity) getActivity()).getFlow().getLaunchMode() == 1) {
                                    play(videoPlayerLibsTmp);
                                }
                            } else if(mActivity instanceof AlbumPlayRoomActivity) {
                                if (((AlbumPlayRoomActivity) getActivity()).getFlow().getLaunchMode() == 1) {
                                    play(videoPlayerLibsTmp);
                                }
                            }
                        } else {

                            LogInfo.log("hong", "playNext------2");
                            play(videoPlayerLibsTmp);
                        }
                    }
                    return;
                } else {
                    if (pageSize * (page - 1) + pos + 1 < totle) {
                        isPlayListLastVideo = (pageSize * (page - 1) + pos + 1 == totle - 1);
                        if (pos < videoListPlayerLibs.size()) {
                            if (pos + 1 == videoListPlayerLibs.size()) {// 本页最后一条数据
                                if (videos.containsKey(page + 1)) {// 如果已经有下页数据，播放
                                    VideoListBean list = videos.get(page + 1);
                                    if (list != null && list.size() > 0) {
                                        this.curPage = page + 1;
                                        VideoBean videoPlayerLibsTmp = list.get(0);
                                        if (LetvUtils.isInFinish(videoPlayerLibsTmp.getId())) {
                                            play(videoPlayerLibsTmp);
                                        } else {
                                            if (lastPlayIsLocalFile && !NetworkUtils.isNetworkAvailable(mActivity)) {// 如果播放下一集之前没有网络则播放下一个已下载的视频
                                                finishPlayer();
                                            } else {
                                                play(videoPlayerLibsTmp);
                                            }
                                        }
                                        return;
                                    } else {
                                        this.curPage = page + 1;
                                        playRecordPlayerLibs = null;
                                        vid = 0;
                                        LogInfo.log("hong", "---playNextNormal---");
                                        setExpandListAndPlayFlag(true);
                                        if (mExpandableListUpdateGroupNotByDateCallBack != null) {
                                            requestAlbumListInfo(curPage, mExpandableListUpdateGroupNotByDateCallBack);
                                        }
                                        else {
                                            requestAlbumListTask();
                                        }
                                        return;
                                    }
                                } else {// 如果没有下页数据，请求再播放
                                    this.curPage = page + 1;
                                    playRecordPlayerLibs = null;
                                    vid = 0;
                                    LogInfo.log("king", "play album playNext page....");
                                    LogInfo.log("hong", "---playNextNormal222---");
                                    setExpandListAndPlayFlag(true);
                                    if (mExpandableListUpdateGroupNotByDateCallBack != null) {
                                        requestAlbumListInfo(curPage, mExpandableListUpdateGroupNotByDateCallBack);
                                    }
                                    else {
                                        requestAlbumListTask();
                                    }
                                    return;
                                }
                            } else {// 本页直接去下集播放
                                VideoBean videoPlayerLibsTmp = videoListPlayerLibs.get(pos + 1);
                                if (LetvUtils.isInFinish(videoPlayerLibsTmp.getId())) {
                                    play(videoPlayerLibsTmp);
                                } else {
                                    if (lastPlayIsLocalFile && !NetworkUtils.isNetworkAvailable(mActivity)) {// 如果播放下一集之前没有网络则播放下一个已下载的视频
                                        finishPlayer();
                                    } else {
                                        play(videoPlayerLibsTmp);
                                    }
                                }
                                return;
                            }
                        } else {
                            finishPlayer();
                        }
                    } else {// 最后一条视频，连播推荐视频
                        /*
                         * 专题视频联播
                         */
                        LogInfo.log("king", "last album video.....");
//                        ArrayList<AlbumNew> albumNewList = getTabAlbumList();
//                        if (albumNewList != null && albumNewList.size() > 0) {
//                            int nSize = albumNewList.size();
//                            long nextAlbumListPid  = -1;
//                            boolean isLastInList = false;   // 是否为albumList中的最后一项
//                            for (int k = 0; k < nSize; k++) {
//                                if (aid == albumNewList.get(k).getAid()) {
//                                    if (k == nSize - 1) {
//                                        isLastInList = true;
//                                        LogInfo.log("hong12", "isLastInList " + true);
//                                    }
//                                    else {
//                                        nextAlbumListPid = albumNewList.get(k + 1).getAid();
//                                        LogInfo.log("hong12", "nextAlbumListPid " + nextAlbumListPid);
//                                    }
//                                    break;
//                                }
//                            }
//
//                            if (!isLastInList) {
//                                notifyToRefreshEpisode(nextAlbumListPid);
//                            }
//                            else {
//                                playVideoRecommend();
//                            }
//                        }
//                        else if (videoRecommendList != null && videoRecommendList.size() > 0) {
//                            playVideoRecommend();
//                        } else {
//                            hasNext();
//                            playVideoRecommend();
////                            finishPlayer();
//                        }
                        finishPlayer();
                    }
                }
            }
        } else {
            /*
             * 专题视频联播
             */
            ArrayList<AlbumNew> albumNewList = getTabAlbumList();
            if (albumNewList != null && albumNewList.size() > 0) {
                int nSize = albumNewList.size();
                long nextAlbumListPid  = -1;
                boolean isLastInList = false;   // 是否为albumList中的最后一项
                int k = 0;
                for (k = 0; k < nSize; k++) {
                    if (aid == albumNewList.get(k).getAid()) {
                        if (k == nSize - 1) {
                            isLastInList = true;
                        }
                        else {
                            nextAlbumListPid = albumNewList.get(k + 1).getAid();
                        }
                        break;
                    }
                }
                
                if (!isLastInList) {                                
                    notifyToRefreshEpisode(nextAlbumListPid);
                }
                else {
                    playVideoRecommend();
                }
            }
            else if (videoRecommendList != null && videoRecommendList.size() > 0) {
                LogInfo.log("king", "play videoRecommend....");
                playVideoRecommend();
            } else {
                hasNext();
//                finishPlayer();
            }
        }
    }

    /**
     * 按年月请求的视频列表续播策略
     * */
    public void playNextByDate() {
        /*
         * 续播之后，更新看点状态
         */
        isRefreshDataAfterRequestPlayUrl = true;
        LogInfo.log("hong", "---playNextByDate()---");
        LogInfo.log("clf", "playNextByDate");
        boolean lastPlayIsLocalFile = isLocalFile;
        VideoBean v = videoBean;
        if (albumNewListByDatePlayerLibs != null && albumNewListByDatePlayerLibs.getYearList() != null
                && albumNewListByDatePlayerLibs.getYearList().size() != 0) {
            isLocalFile = false;
            filePath = null;
            HashMap<String, MonthList> yearList = albumNewListByDatePlayerLibs.getYearList();
            Iterator<String> yearKeys = yearList.keySet().iterator();
            String yearKey = "";
            String monthKey = "";
            boolean isFind = false;
            while (yearKeys.hasNext()) {
                yearKey = yearKeys.next();
                MonthList monthList = yearList.get(yearKey);
                if (monthList.size() == 0) {
                    continue;
                }
                if (monthList != null && monthList.size() > 0) {
                    Iterator<String> monthKeys = monthList.keySet().iterator();
                    while (monthKeys.hasNext()) {
                        monthKey = monthKeys.next();
                        ArrayList<VideoBean> videoList = monthList.get(monthKey);
                        if (videoList.size() == 0) {
                            continue;
                        }
                        if (videoList != null && videoList.size() > 0) {
                            int size = videoList.size();
                            int pos = -1;
                            for (int i = 0; i < size; i++) {
                                if (v.getId() == videoList.get(i).getId()) {
                                    pos = i;
                                    isFind = true;
                                    break;
                                }
                            }
                            if (isFind) {
                                if (pos == size - 1) { // 本期最后一个视频，需要播下一期第一个视频
                                    if (monthKeys.hasNext()) {
                                        String nextMonthkey = monthKeys.next();
                                        LogInfo.log("king", "nextMonthkey = " + nextMonthkey);
                                        ArrayList<VideoBean> newVideoList = monthList.get(nextMonthkey);
                                        if (newVideoList != null && newVideoList.size() > 0) { // 数据已经存在
                                            LogInfo.log("king", "nextMonthkey has data ");
                                            VideoBean videoPlayerLibsTmp = newVideoList.get(0);
                                            if (LetvUtils.isInFinish(videoPlayerLibsTmp.getId())) {
                                                play(videoPlayerLibsTmp);
                                            } else {
                                                if (lastPlayIsLocalFile && !NetworkUtils.isNetworkAvailable(mActivity)) {// 如果播放下一集之前没有网络则播放下一个已下载的视频
                                                    finishPlayer();
                                                } else {
                                                    play(videoPlayerLibsTmp);
                                                }
                                            }
                                        } else { // 数据不存在
                                            playRecordPlayerLibs = null;
                                            setVid(0);
                                            LogInfo.log("king", "nextMonthkey request data year = " + yearKey
                                                    + " ,nextMonthKey = " + nextMonthkey);
                                            new RequestAlbumListInfoByDate(true, true, yearKey, nextMonthkey, aid, vid)
                                                    .start();
                                        }
                                        return;
                                    } else {
                                        if (!yearKeys.hasNext()) {
                                            isFind = false;
                                        }
                                        break;
                                    }
                                } else { // 本期非最后一个视频 本期数据肯定都存在
                                    isPlayListLastVideo = (pos + 1 == size - 1) && !yearKeys.hasNext()
                                            && !monthKeys.hasNext();
                                    VideoBean videoPlayerLibsTmp = videoList.get(pos + 1);
                                    if (LetvUtils.isInFinish(videoPlayerLibsTmp.getId())) {
                                        play(videoPlayerLibsTmp);
                                    } else {
                                        if (lastPlayIsLocalFile && !NetworkUtils.isNetworkAvailable(mActivity)) {// 如果播放下一集之前没有网络则播放下一个已下载的视频
                                            finishPlayer();
                                        } else {
                                            play(videoPlayerLibsTmp);
                                        }
                                    }
                                    return;
                                }
                            }
                        } else { // 数据不存在
                            playRecordPlayerLibs = null;
                            setVid(0);
                            LogInfo.log("king", "nextYearkey request data year = " + yearKey + " ,monthKey = "
                                    + monthKey);
                            new RequestAlbumListInfoByDate(true, true, yearKey, monthKey, aid, vid).start();
                            break;
                        }
                    }
                }
            }
            if (!isFind) {
                finishPlayer();
//                if (videoRecommendList != null && videoRecommendList.size() > 0) {
//                    playVideoRecommend();
//                } else {
//                    requestPlayRecommendTask();
//                }
            }
        }
        else {
            finishPlayer();
//            if (videoRecommendList != null && videoRecommendList.size() > 0) {
//                playVideoRecommend();
//            } else {
//                requestPlayRecommendTask();
//            }
        }
    }

    /*
     * 解析点播数据集合
     */
    private void parseEpisodeData(TabAllDataBean data) {
        if (data != null) {
            /*
             * The begin of assign data to specify variable
             */
            if (mTabAllDataBean.getVideoInfo() != null) {
                /*
                 * 选中态取播放记录vid
                 */
                vid = mTabAllDataBean.getVideoInfo().getId();
                cid = mTabAllDataBean.getVideoInfo().getCid();
                aid = mTabAllDataBean.getVideoInfo().getPid();
                videoBean = mTabAllDataBean.getVideoInfo();
            }

            /*
             * 针对VideoInfo返回数据可能为空的情况
             */
            if (mTabAllDataBean.getAlbumInfo() != null) {
                /*
                 * 选中态取播放记录vid
                 */
                 if (vid == 0) {
                     vid = mTabAllDataBean.getAlbumInfo().getId();
                 }
                if (cid == 0) {
                    cid = mTabAllDataBean.getAlbumInfo().getCid();
                }
                setAlbumAndSysInfo(mTabAllDataBean.getAlbumInfo());
            }

            int diaplayStyle = 1;
            String strStyle = mTabAllDataBean.getTabVideoList().getTabIndicatorData().getStyle();
            if (!TextUtils.isEmpty(strStyle)) {
                diaplayStyle = Integer.valueOf(strStyle);
                mDisplayStyle = diaplayStyle;
            }
            
            isVideoNormal = mTabAllDataBean.isNormalVideo();
            if (isVideoNormal) {
                String strPageNum = mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList().getPagenum();
                if (!TextUtils.isEmpty(strPageNum)) {
                    curPage = Integer.valueOf(strPageNum);
                }
                String strTotalNum = mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList()
                        .getTotalNum();
                if (!TextUtils.isEmpty(strTotalNum) && TextUtils.isDigitsOnly(strTotalNum)) {
                    totle = Integer.valueOf(strTotalNum);
                    if (diaplayStyle == 1) {
                        TabVideoListBean tabVideoListBean = mTabAllDataBean.getTabVideoList().getTabIndicatorData().getVideoList();
                        if (tabVideoListBean.getPreviewList() != null && tabVideoListBean.getPreviewList().size() > 0) {
                            totle += tabVideoListBean.getPreviewList().size();
                        }
                    }
                }

                if (diaplayStyle == 1 || diaplayStyle == 2) {
                    isRequestAlbumListByDate = false;

                    videos.clear();
                    VideoListBean videoList = new VideoListBean();
                    TabVideoListBean tabVideoListBean = mTabAllDataBean.getTabVideoList().getTabIndicatorData()
                            .getVideoList();
                    videoList.addAll(tabVideoListBean.getVideoInfoList());
                     if (diaplayStyle == 1) {
                         if (tabVideoListBean.getPreviewList() != null && tabVideoListBean.getPreviewList().size() > 0) {
                             videoList.addAll(tabVideoListBean.getPreviewList());
                         }
                     }
                    if (!TextUtils.isEmpty(tabVideoListBean.getPagenum())) {
                        videoList.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
                    }
                    if (!TextUtils.isEmpty(tabVideoListBean.getTotalNum())) {
                        videoList.setTotalNum(Integer.valueOf(tabVideoListBean.getTotalNum()));
                    }
                    if (!TextUtils.isEmpty(tabVideoListBean.getEpisodeNum())) {
                        videoList.setEpisodeNum(Integer.valueOf(tabVideoListBean.getEpisodeNum()));
                    }
                    if (!TextUtils.isEmpty(tabVideoListBean.getShowOuterVideolist())) {
                        videoList.setShowOuterVideolist(Integer.valueOf(tabVideoListBean.getShowOuterVideolist()));
                    }
                    if (!TextUtils.isEmpty(tabVideoListBean.getVarietyShow())) {
                        videoList.setVarietyShow(Integer.valueOf(tabVideoListBean.getVarietyShow()));
                    }
                    if (!TextUtils.isEmpty(tabVideoListBean.getPagenum())) {
                        tabVideoListBean.setPagenum(String.valueOf(curPage));
                    }
                    videos.put(curPage, videoList);
                } else if (diaplayStyle == 3) {
                    isRequestAlbumListByDate = true;

                    albumNewListByDatePlayerLibs = mTabAllDataBean.getTabVideoList().getTabIndicatorData()
                            .getVideoList().getAlbumNewListByDatePlayerLibs();
                }
            }
            else {
                isRequestAlbumListByDate = false;                    

                videos.clear();
                VideoListBean videoList = new VideoListBean();
                videoList.clear();
                TabVideoListBean tabVideoListBean = mTabAllDataBean.getTabRelate().getTabIndicatorData().getVideoList();
                if (tabVideoListBean.getRecDataList() != null && tabVideoListBean.getRecDataList().size() > 0) {
                    videoList.addAll(tabVideoListBean.getRecDataList());
                }
                else if (tabVideoListBean.getVideoInfoList() != null && tabVideoListBean.getVideoInfoList().size() > 0) {
                    videoList.addAll(tabVideoListBean.getVideoInfoList());
                }
                
                VideoBean playingVideoBean = tabVideoListBean.getSelfVideo();
                if (playingVideoBean != null) {
                    boolean isFindInList = false;
                    int nSize = videoList.size();
                    for (int i = 0; i < nSize; i++) {
                        if (playingVideoBean.getVid() == videoList.get(i).getVid()) {
                            isFindInList = true;
                            break;
                        }
                    } 
                    if (!isFindInList) {
                        videoList.add(0, playingVideoBean);
                        /*
                         *  兼容recData为空的极端情况， 去除size判断,避免续播失败  && tabVideoListBean.getRecDataList().size() > 0
                         */
                        if (tabVideoListBean.getRecDataList() != null) {    
                            tabVideoListBean.getRecDataList().add(0, playingVideoBean);
                        }
                        /*
                         *  兼容videoInfo为空的极端情况， 去除size判断,避免续播失败  && tabVideoListBean.getVideoInfoList().size() > 0
                         */
                        else if (tabVideoListBean.getVideoInfoList() != null) { 
                            tabVideoListBean.getVideoInfoList().add(0, playingVideoBean);
                        }
                    }
                }
                totle = tabVideoListBean.getRecDataList().size();
                
                if (!TextUtils.isEmpty(tabVideoListBean.getShowOuterVideolist())) {
                    videoList.setShowOuterVideolist(Integer.valueOf(tabVideoListBean.getShowOuterVideolist()));
                }
                if (!TextUtils.isEmpty(tabVideoListBean.getVarietyShow())) {
                    videoList.setVarietyShow(Integer.valueOf(tabVideoListBean.getVarietyShow()));
                }
                if (!TextUtils.isEmpty(tabVideoListBean.getPagenum()) && TextUtils.isDigitsOnly(tabVideoListBean.getPagenum())) {
                    videoList.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
                }
                else {
                    videoList.setPagenum(curPage);
                }
                videos.put(curPage, videoList);
            }

            checkFullControllerFragmentVideoType(getVideoBean(), getAlbum());
        }
    }

    /**
     * 根据 videoBean 和 album 确定 videoType
     * @param videoBean
     * @param album
     */
    private void checkFullControllerFragmentVideoType(VideoBean videoBean, AlbumNew album ) {
        if (mActivity instanceof AlbumPlayActivity && ((AlbumPlayActivity) mActivity).getFullControllerFragment() != null) {
            judgeVideoByVideoAlbum(videoBean, album);
            ((AlbumPlayActivity) mActivity).getFullControllerFragment().checkVideoType();
        } else if(mActivity instanceof AlbumPlayRoomActivity && ((AlbumPlayRoomActivity) mActivity).getFullControllerFragment() != null) {
            judgeVideoByVideoAlbum(videoBean, album);
            ((AlbumPlayRoomActivity) mActivity).getFullControllerFragment().checkVideoType();
        }
    }

    /*
     * 解析专题数据集合
     */
    private void parseTopicEpisodeData(TabTopicAllDataBean data) {
        if (data != null) {
            String strStyle = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().getStyle();
            if (!TextUtils.isEmpty(strStyle) && TextUtils.isDigitsOnly(strStyle)) {
                type = Integer.valueOf(strStyle);
            }            
            
            if (type == GRIDVIEW_LIST_CONSTANT && !BaseTypeUtils.isListEmpty(mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().getVideoInfoList())) {
                mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().setStyle(GRIDVIEW_LIST_CONSTANT + "");
                parseTopicGridData();
            }
            else if (type == VIDEO_LIST_CONSTANT
                    && !BaseTypeUtils.isListEmpty(mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().getRecDataList())) {
                mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().setStyle(VIDEO_ITEM_LIST_CONSTANT + "");
                parseTopicListData();
            }
            else {
                mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().setStyle(VIDEO_ITEM_LIST_CONSTANT + "");
                parseTopicListData();
            }
            
            if (!TextUtils.isEmpty(strStyle) && TextUtils.isDigitsOnly(strStyle)) {
                isList = getIsList(strStyle);// 初始化，是宫格合适列表
            }
            
            checkFullControllerFragmentVideoType(getVideoBean(), getAlbum());
        }
    }
    
    private void parseTopicGridData() {

        /*
         * 针对VideoInfo返回数据可能为空的情况
         */
        AlbumNew albumNew = mTabTopicAllDataBean.getAlumNewByPid(getPid());
        if (albumNew != null) {
                /*
                 * 选中态取播放记录vid
                 */
             if (vid == 0) {
             vid = albumNew.getId();
             }
            if (cid == 0) {
                cid = albumNew.getCid();
            }
            setAlbumAndSysInfo(albumNew);
        }

        isVideoNormal = mTabTopicAllDataBean.isNormalVideo();
        
        String strPageNum = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().getPagenum();
        if (!TextUtils.isEmpty(strPageNum)) {
            curPage = Integer.valueOf(strPageNum);
        }
        String strTotalNum = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().getTotalNum();
        if (!TextUtils.isEmpty(strTotalNum)) {
            totle = Integer.valueOf(strTotalNum);
        }

        int diaplayStyle = 1;
        String strStyle = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().getStyle();
        if (!TextUtils.isEmpty(strStyle)) {
            diaplayStyle = Integer.valueOf(strStyle);
            mDisplayStyle = diaplayStyle;
        }

        if (diaplayStyle == 1 || diaplayStyle == 2) {
            isRequestAlbumListByDate = false;                    

            videos.clear();
            VideoListBean videoList = new VideoListBean();
            TabVideoListBean tabVideoListBean = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList();
            videoList.addAll(tabVideoListBean.getVideoInfoList());
             if (diaplayStyle == 1) {
                 if (tabVideoListBean.getPreviewList() != null && tabVideoListBean.getPreviewList().size() > 0) {
                     videoList.addAll(tabVideoListBean.getPreviewList());
                 }
             }
            if (!TextUtils.isEmpty(tabVideoListBean.getPagenum())) {
                videoList.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getTotalNum())) {
                videoList.setTotalNum(Integer.valueOf(tabVideoListBean.getTotalNum()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getEpisodeNum())) {
                videoList.setEpisodeNum(Integer.valueOf(tabVideoListBean.getEpisodeNum()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getShowOuterVideolist())) {
                videoList.setShowOuterVideolist(Integer.valueOf(tabVideoListBean.getShowOuterVideolist()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getVarietyShow())) {
                videoList.setVarietyShow(Integer.valueOf(tabVideoListBean.getVarietyShow()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getPagenum())) {
                tabVideoListBean.setPagenum(tabVideoListBean.getPagenum());
            }
            else {
                tabVideoListBean.setPagenum(String.valueOf(curPage));
            }
            videos.put(curPage, videoList);
        } else if (diaplayStyle == 3) {
            isRequestAlbumListByDate = true;

            albumNewListByDatePlayerLibs = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList()
                    .getAlbumNewListByDatePlayerLibs();
        }
    }
    
    private void parseTopicListData() {

        /*
         * 针对VideoInfo返回数据可能为空的情况
         */
        AlbumNew albumNew = mTabTopicAllDataBean.getAlumNewByPid(getPid());
        if (albumNew != null) {
                /*
                 * 选中态取播放记录vid
                 */
            // if (vid == 0) {
            // vid = mTabTopicAllDataBean.getAlbumInfo().getId();
            // }
            if (cid == 0) {
                cid = albumNew.getCid();
            }
            setAlbumAndSysInfo(albumNew);
        }
        
        isVideoNormal = mTabTopicAllDataBean.isNormalVideo();         

            int diaplayStyle = GRIDVIEW_LIST_CONSTANT;
            String strStyle = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().getStyle();
            if (!TextUtils.isEmpty(strStyle)) {
                diaplayStyle = Integer.valueOf(strStyle);
                mDisplayStyle = diaplayStyle;
            }

            if (diaplayStyle == GRIDVIEW_LIST_CONSTANT || diaplayStyle == VIDEO_ITEM_LIST_CONSTANT) {
                isRequestAlbumListByDate = false;                    

                videos.clear();
                VideoListBean videoList = new VideoListBean();
                videoList.clear();
                TabVideoListBean tabVideoListBean = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList();
                if (tabVideoListBean.getRecDataList() != null && tabVideoListBean.getRecDataList().size() > 0) {
                    videoList.addAll(tabVideoListBean.getRecDataList());
                }
                else if (tabVideoListBean.getVideoInfoList() != null && tabVideoListBean.getVideoInfoList().size() > 0) {
                    videoList.addAll(tabVideoListBean.getVideoInfoList());
                }
                
                VideoBean playingVideoBean = tabVideoListBean.getSelfVideo();
                if (playingVideoBean != null) {
                    boolean isFindInList = false;
                    int nSize = videoList.size();
                    for (int i = 0; i < nSize; i++) {
                        if (playingVideoBean.getVid() == videoList.get(i).getVid()) {
                            isFindInList = true;
                            break;
                        }
                    } 
                    if (!isFindInList) {
                        videoList.add(0, playingVideoBean);
                        /*
                         *  兼容recData为空的极端情况， 去除size判断,避免续播失败  && tabVideoListBean.getRecDataList().size() > 0
                         */
                        if (tabVideoListBean.getRecDataList() != null) {    
                            tabVideoListBean.getRecDataList().add(0, playingVideoBean);
                        }
                        /*
                         *  兼容videoInfo为空的极端情况， 去除size判断,避免续播失败  && tabVideoListBean.getVideoInfoList().size() > 0
                         */
                        else if (tabVideoListBean.getVideoInfoList() != null) { 
                            tabVideoListBean.getVideoInfoList().add(0, playingVideoBean);
                        }
                    }
                }
                
                if (!TextUtils.isEmpty(tabVideoListBean.getShowOuterVideolist())) {
                    videoList.setShowOuterVideolist(Integer.valueOf(tabVideoListBean.getShowOuterVideolist()));
                }
                if (!TextUtils.isEmpty(tabVideoListBean.getVarietyShow())) {
                    videoList.setVarietyShow(Integer.valueOf(tabVideoListBean.getVarietyShow()));
                }
                if (!TextUtils.isEmpty(tabVideoListBean.getPagenum()) && TextUtils.isDigitsOnly(tabVideoListBean.getPagenum())) {
                    videoList.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
                }
                else {
                    videoList.setPagenum(curPage);
                }
                videos.put(curPage, videoList);
            } else if (diaplayStyle == 3) {
                isRequestAlbumListByDate = true;

                albumNewListByDatePlayerLibs = mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList()
                        .getAlbumNewListByDatePlayerLibs();
            }
    }
    
    
    private void parseTopicVideoListData(TabTopicVideoListBean data) {
        if (data != null) {            
            String strStyle = data.getStyle();
            VideoBean videoBean = null;
            
            if (strStyle.equals(GRIDVIEW_LIST_CONSTANT_STR)) {
            	mTabTopicVideoListBean.getTabVideoListBean().setStyle(GRIDVIEW_LIST_CONSTANT_STR);
                parseTopicVideoListGridData(data);                
                                
                if (data.getTabVideoListBean() != null) {
                    if (data.getTabVideoListBean().getVideoInfoList() != null
                        && data.getTabVideoListBean().getVideoInfoList().size() > 0) {
                        videoBean = data.getTabVideoListBean().getVideoInfoList().get(0);
                    }                    
                
                    if (videoBean != null) {
                        play(videoBean);
                    }
                }
            }
            else if (strStyle.equals(VIDEO_LIST_CONSTANT_STR)) {
            	mTabTopicVideoListBean.getTabVideoListBean().setStyle(VIDEO_LIST_CONSTANT_STR);
                parseTopicVideoListItemData(data);
                
                if (data.getTabVideoListBean() != null) {
                    if (data.getTabVideoListBean().getVideoInfoList() != null
                            && data.getTabVideoListBean().getVideoInfoList().size() > 0) {
                        videoBean = data.getTabVideoListBean().getVideoInfoList().get(0);
                    }
                    
                    if (videoBean != null) {
                        play(videoBean);
                    }
                }
            }
            
            if (!TextUtils.isEmpty(strStyle) && TextUtils.isDigitsOnly(strStyle)) {
                isList = getIsList(strStyle);// 初始化，是宫格合适列表
            }
            
            checkFullControllerFragmentVideoType(videoBean != null ? videoBean : getVideoBean(), getAlbum());
        }
    }
    
    private void parseTopicVideoListGridData(TabTopicVideoListBean tabTopicVideoListBean) {        
        String totalNum = tabTopicVideoListBean.getTabVideoListBean().getTotalNum();
        if (!TextUtils.isEmpty(totalNum) && TextUtils.isDigitsOnly(totalNum)) {
            totle = Integer.valueOf(totalNum);
        }

        isVideoNormal = true;
        int diaplayStyle = GRIDVIEW_LIST_CONSTANT;
        String strStyle = tabTopicVideoListBean.getTabVideoListBean().getStyle();
        if (!TextUtils.isEmpty(strStyle) && TextUtils.isDigitsOnly(strStyle)) {
            diaplayStyle = Integer.valueOf(strStyle);
            mDisplayStyle = diaplayStyle;
        }

        if (diaplayStyle == GRIDVIEW_LIST_CONSTANT) {
            isRequestAlbumListByDate = false;                    
            String strPageNum = tabTopicVideoListBean.getTabVideoListBean().getPagenum();
            if (!TextUtils.isEmpty(strPageNum)) {
                curPage = Integer.valueOf(strPageNum);
            }
            String strTotalNum = tabTopicVideoListBean.getTabVideoListBean().getTotalNum();
            if (!TextUtils.isEmpty(strTotalNum)) {
                totle = Integer.valueOf(strTotalNum);
            }
            
            videos.clear();
            VideoListBean videoList = new VideoListBean();
            TabVideoListBean tabVideoListBean = tabTopicVideoListBean.getTabVideoListBean();
            videoList.addAll(tabVideoListBean.getVideoInfoList());
            
            if (!TextUtils.isEmpty(tabVideoListBean.getPagenum())) {
                videoList.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getTotalNum())) {
                videoList.setTotalNum(Integer.valueOf(tabVideoListBean.getTotalNum()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getEpisodeNum())) {
                videoList.setEpisodeNum(Integer.valueOf(tabVideoListBean.getEpisodeNum()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getShowOuterVideolist())) {
                videoList.setShowOuterVideolist(Integer.valueOf(tabVideoListBean.getShowOuterVideolist()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getVarietyShow())) {
                videoList.setVarietyShow(Integer.valueOf(tabVideoListBean.getVarietyShow()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getPagenum())
                    && TextUtils.isDigitsOnly(tabVideoListBean.getPagenum())) {
                videoList.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
            }
            else {
                videoList.setPagenum(curPage);
            }
            videos.put(curPage, videoList);
            
            convertVideoListToTabBean(tabTopicVideoListBean);
        }
    }
    
    private void convertVideoListToTabBean(TabTopicVideoListBean tabTopicVideoListBean) {
    	if (tabTopicVideoListBean != null && tabTopicVideoListBean.getTabVideoListBean() != null) {
    		TabVideoListBean tabVideoListBean = tabTopicVideoListBean.getTabVideoListBean();
    		mTabVideoListBean.setVideoInfoList(tabVideoListBean.getVideoInfoList());
        	mTabVideoListBean.setPagenum(tabVideoListBean.getPagenum());
        	mTabVideoListBean.setTotalNum(tabVideoListBean.getTotalNum());
        	mTabVideoListBean.setEpisodeNum(tabVideoListBean.getEpisodeNum());
        	mTabVideoListBean.setShowOuterVideolist(tabVideoListBean.getShowOuterVideolist());
        	mTabVideoListBean.setVarietyShow(tabVideoListBean.getVarietyShow());
        	mTabVideoListBean.setStyle(tabTopicVideoListBean.getStyle());
    	}
    }
    
    private void parseTopicVideoListItemData(TabTopicVideoListBean tabTopicVideoListBean) {
        /*
         * 默认为正片
         */
        isVideoNormal = true;
        
        String totalNum = tabTopicVideoListBean.getTabVideoListBean().getTotalNum();
        if (!TextUtils.isEmpty(totalNum) && TextUtils.isDigitsOnly(totalNum)) {
            totle = Integer.valueOf(totalNum);
        }

        int diaplayStyle = VIDEO_LIST_CONSTANT;
        String strStyle = tabTopicVideoListBean.getStyle();
        if (!TextUtils.isEmpty(strStyle) && TextUtils.isDigitsOnly(strStyle)) {
            diaplayStyle = Integer.valueOf(strStyle);
            mDisplayStyle = diaplayStyle;
        }
 
        if (diaplayStyle == VIDEO_LIST_CONSTANT) {
            isRequestAlbumListByDate = false;                    

            videos.clear();
            VideoListBean videoList = new VideoListBean();
            videoList.clear();
            TabVideoListBean tabVideoListBean = tabTopicVideoListBean.getTabVideoListBean();

            if (tabVideoListBean.getVideoInfoList() != null && tabVideoListBean.getVideoInfoList().size() > 0) {
                videoList.addAll(tabVideoListBean.getVideoInfoList());
            }
            
            VideoBean playingVideoBean = tabVideoListBean.getSelfVideo();
            if (playingVideoBean != null) {
                boolean isFindInList = false;
                int nSize = videoList.size();
                for (int i = 0; i < nSize; i++) {
                    if (playingVideoBean.getVid() == videoList.get(i).getVid()) {
                        isFindInList = true;
                        break;
                    }
                } 
                if (!isFindInList) {
                    videoList.add(0, playingVideoBean);
                    if (tabVideoListBean.getVideoInfoList() != null) {
                        tabVideoListBean.getVideoInfoList().add(0, playingVideoBean);
                    }
                }
            }
            
            if (!TextUtils.isEmpty(tabVideoListBean.getShowOuterVideolist())) {
                videoList.setShowOuterVideolist(Integer.valueOf(tabVideoListBean.getShowOuterVideolist()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getVarietyShow())) {
                videoList.setVarietyShow(Integer.valueOf(tabVideoListBean.getVarietyShow()));
            }
            if (!TextUtils.isEmpty(tabVideoListBean.getPagenum()) 
                    && TextUtils.isDigitsOnly(tabVideoListBean.getPagenum())) {
                videoList.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
            }
            else {
                videoList.setPagenum(curPage);
            }
            videos.put(curPage, videoList);
            
            convertVideoListToTabBean(tabTopicVideoListBean);
        }
    }
    
    // ###########################################
    /*
     * The below is only for topic tab page
     */
    
    public TabSubject getTabSubject() {
        if (mTabTopicAllDataBean.getTabTopicZtList() != null 
                && mTabTopicAllDataBean.getTabTopicZtList().getSubject() != null) {
            return mTabTopicAllDataBean.getTabTopicZtList().getSubject();
        }
        else {
            return null;
        }
    }
    
    public ArrayList<AlbumNew> getTabAlbumList() {
        if (mTabTopicAllDataBean.getTabTopicZtList() != null
                && mTabTopicAllDataBean.getTabTopicZtList().getTabAlbumList() != null) {
            return mTabTopicAllDataBean.getTabTopicZtList().getTabAlbumList();
        }
        else {
            return null;
        }
    }
    
    public void setTabVideoListBean(TabVideoListBean tabVideoListBean) {
        mTabVideoListBean = tabVideoListBean;
    }
    
    public TabVideoListBean getTabVideoListBean() {
        if (mTabVideoListBean.getVideoInfoList() != null
                && mTabVideoListBean.getVideoInfoList().size() > 0) {
            return mTabVideoListBean;
        }
        else if (mTabTopicAllDataBean.getTabTopicZtList() != null
                && mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList() != null
                && mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList().getVideoInfoList() != null) {
            return mTabTopicAllDataBean.getTabTopicZtList().getTabVideoList();
        }
        else {
            return null;
        }
    }
    
    public TabVideoListBean getTabVideoItemListBean() {
        if (mTabTopicVideoListBean.getTabVideoListBean() != null
                && mTabTopicVideoListBean.getTabVideoListBean().getRecDataList() != null) {
            return mTabTopicVideoListBean.getTabVideoListBean();
        }
        else {
            return null;
        }
    }
    
    private void notifyToRefreshEpisode(long pid) {
        Bundle bundle = new Bundle();
        bundle.putLong(CURRENT_TOPIC_PID, pid);
        if (videosCallBack != null) {
            videosCallBack.notify(bundle);
        }
        if (topicVideoListCallBack != null) {
            topicVideoListCallBackState = PlayAlbumControllerCallBack.STATE_NEXT;
            topicVideoListCallBack.notify(topicVideoListCallBackState);
        }
    }
    
    public void setVideoRecommend(HomeMetaData recommend) {
        videoRecommend = recommend;
        if (mActivity instanceof AlbumPlayActivity && ((AlbumPlayActivity) mActivity).getFlow() != null) {
            ((AlbumPlayActivity) mActivity).getFlow().setVideoRecommend(recommend);
        } else if(mActivity instanceof AlbumPlayRoomActivity && ((AlbumPlayRoomActivity) mActivity).getFlow() != null) {
            ((AlbumPlayRoomActivity) mActivity).getFlow().setVideoRecommend(recommend);
        }
    }

    private void sysPlayingViedo(VideoBean videoBean){
        this.videoBean = videoBean;
        this.vid = videoBean.getVid();
        this.aid = videoBean.getPid();
        this.cid = videoBean.getCid();
    }

    @Override
    public void setPlayingVideoBean(VideoBean videoBean) {
        sysPlayingViedo(videoBean);
        
        //刷新详情评论显示
        commentCallBackState = PlayAlbumControllerCallBack.STATE_REFRESH_DATA;
        if (commentCallBack != null) {
            commentCallBack.notify(PlayAlbumControllerCallBack.STATE_REFRESH_DATA);
        }

        //刷新剧集页
        videosCallBackState = PlayAlbumControllerCallBack.STATE_REFRESH_DATA;
        if (videosCallBack != null) {
            videosCallBack.notify(PlayAlbumControllerCallBack.STATE_REFRESH_DATA);
        }        
        //刷新Tabs签页面
        tabsBaseCallBackState = PlayAlbumControllerCallBack.STATE_REFRESH_DATA;
        if (tabsBaseCallBack != null) {
            tabsBaseCallBack.notify(PlayAlbumControllerCallBack.STATE_REFRESH_DATA);
        }

        //专题列表页
        topicVideoListCallBackState = PlayAlbumControllerCallBack.STATE_REFRESH_DATA;
        if (topicVideoListCallBack != null) {
            topicVideoListCallBack.notify(PlayAlbumControllerCallBack.STATE_REFRESH_DATA);
        }

        //看点入口处
//        if (!BaseTypeUtils.isListEmpty(videoBean.getWatchingFocusList())) {
//            StatisticsUtils.staticticsInfoPost(LetvApplication.getInstance(), "19", "h25", null, -1, null, "031", videoBean.getCid() + "", videoBean.getPid()
//                    + "", videoBean.getId() + "", "-", "-");
//            LogInfo.LogStatistics("看点统计上报 入口");
//        }
        hasNext();
    }

    public long getPlayRecordNextVid() {
        return playRecordNextVid;
    }

    public void setPlayRecordNextVid(long playRecordNextVid) {
        this.playRecordNextVid = playRecordNextVid;
    }

	public boolean isPlayFromAlbumFlag() {
		return mPlayFromAlbumFlag;
	}

	public void setPlayFromAlbumFlag(boolean playFromAlbumFlag) {
		this.mPlayFromAlbumFlag = playFromAlbumFlag;
	} 
	public void  setFullRefreshData(FullRefreshData data) {
		fullRefesh = data;
	}

    public boolean isExpandListAndPlayFlag() {
        return isExpandListAndPlayFlag;
    }

    public void setExpandListAndPlayFlag(boolean isExpandListAndPlayFlag) {
        this.isExpandListAndPlayFlag = isExpandListAndPlayFlag;
    }


    //全屏刷新剧集界面
    public interface FullRefreshData {
        void refreshDataForFull(boolean isSuccess);
    }

    public interface DBDownlaodInterface {
        void onQueryDownloadVideoComplete();
    }

//    public void setApplicationVideoList() {
//        VideoListBean videoListBean = new VideoListBean();
//        TabVideoListBean tabVideoListBean = getTabVideoListData().getVideoList();
//        if (tabVideoListBean != null) {
//            // 1 正片
//            if (tabVideoListBean.getVideoInfoList() != null) {
//                if (isPlayFromAlbumFlag()) {
//                    if (getTabVideoListData() != null
//                    		&& getTabVideoListData().getStyle().equals("1")
//                            && Integer.valueOf(getTabVideoListData().getVideoList().getTotalNum()) > 100) {
//                        videoListBean.addAll(videos.get(curPage));
//                    } else {
//                        videoListBean.addAll(tabVideoListBean.getVideoInfoList());
//                    }
//                } else {
//                    if (getTabVideoListBean() != null
//                            && getTabVideoListBean().getVideoInfoList() != null
//                            && getTabVideoListBean().getVideoInfoList().size() > 0) {
//                        if (mTabAllDataBean != null) {
//                            videoListBean.addAll(getTabVideoListBean().getVideoInfoList());
//                        }
//                    }
//                }
//
//                if (!TextUtils.isEmpty(tabVideoListBean.getEpisodeNum()) && TextUtils.isDigitsOnly(tabVideoListBean.getEpisodeNum())) {
//                    videoListBean.setEpisodeNum(Integer.valueOf(tabVideoListBean.getEpisodeNum()));
//                }
//                if (!TextUtils.isEmpty(tabVideoListBean.getPagenum()) && TextUtils.isDigitsOnly(tabVideoListBean.getEpisodeNum())) {
//                    videoListBean.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
//                }
//                if (!TextUtils.isEmpty(tabVideoListBean.getShowOuterVideolist()) && TextUtils.isDigitsOnly(tabVideoListBean.getEpisodeNum())) {
//                    videoListBean.setShowOuterVideolist(Integer.valueOf(tabVideoListBean.getShowOuterVideolist()));
//                }
//                if (!TextUtils.isEmpty(tabVideoListBean.getTotalNum()) && TextUtils.isDigitsOnly(tabVideoListBean.getEpisodeNum())) {
//                    videoListBean.setTotalNum(Integer.valueOf(tabVideoListBean.getTotalNum()));
//                }
//                if (!TextUtils.isEmpty(tabVideoListBean.getVarietyShow()) && TextUtils.isDigitsOnly(tabVideoListBean.getEpisodeNum())) {
//                    videoListBean.setVarietyShow(Integer.valueOf(tabVideoListBean.getVarietyShow()));
//                }
//                // 如果list 没有数据，加入当前播放的video
//                if (0 == videoListBean.size()) {
//                    videoListBean.add(getVideoBean());
//                }
//            }
//
//            // 2 预告片
//            ArrayList<VideoBean> preViewList = tabVideoListBean.getPreviewList();
//            if (null != preViewList) {
//                for (VideoBean preViewBean : preViewList) {
//                    videoListBean.add(preViewBean);
//                }
//            }
//
//            BaseApplication.getInstance().setmVideoList(videoListBean);
//        }
//
//    }
}
